When using ViusalStudio2019 to create code in Unity2022, error CS8032 C# cannot create analyzer instance {0} from {1}: {2}.

I encountered CS8032 when using Unity2022 to create a script in vs2019.

question

First create a script named CS8032WarningFixer under the Assets file

 

Enter these codes in the script 

using System.Linq;
using System.Xml.Linq;
using UnityEditor;
public class CS8032WarningFixer : AssetPostprocessor
{
    private static string OnGeneratedCSProject(string path, string content)
    {
        var document = XDocument.Parse(content);
        document.Root.Descendants()
            .Where(x => x.Name.LocalName == "Analyzer")
            .Where(x => x.Attribute("Include").Value.Contains("Unity.SourceGenerators"))
            .Remove();
        return document.Declaration + System.Environment.NewLine + document.Root;
    }
}

using System.Linq;
using System.Xml.Linq;
using UnityEditor;
public class CS8032WarningFixer : AssetPostprocessor
{
    private static string OnGeneratedCSProject(string path, string content)
    {
        var document = XDocument.Parse(content);
        document.Root.Descendants()
            .Where(x => x.Name.LocalName == "Analyzer")
            .Where(x => x.Attribute("Include").Value.Contains("Unity.SourceGenerators"))
            .Remove();
        return document.Declaration + System.Environment.NewLine + document.Root;
    }
}

Return to unity after saving

Open to your project folder and delete the xxxxxx.sln file 

 Close Unity and restart the project

 After restarting, you will see a folder generated

After reopening the script, the warning disappeared.

 

Guess you like

Origin blog.csdn.net/weixin_45769991/article/details/130693115