Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during the compilation in VisualStudio's msbuild.exe #961

Open
alexkr403 opened this issue Oct 8, 2024 · 0 comments
Open

Error during the compilation in VisualStudio's msbuild.exe #961

alexkr403 opened this issue Oct 8, 2024 · 0 comments

Comments

@alexkr403
Copy link

alexkr403 commented Oct 8, 2024

I try to use the library for Roslyn code generation purposes. The code inside the generator:

public Dictionary<string, string> Create()
{
    var stream = Assembly
        .GetAssembly(typeof(ParametersXmlParser))
        .GetManifestResourceStream("Compatibility_Assembly");

    var module = ModuleDefinition.ReadModule(stream);

    var tagType = module.GetType("Compatibility.Enumerations.Tag");
    var derivedFromAttributeType =
        module.GetType("Compatibility.Attributes.ParameterDerivedFromAttribute");

    var valueToNameLookup = tagType
        .Fields
        .Where(f => f.Name != "value__")
        .ToDictionary(f => (int)f.Constant, f => f.Name);

    var result = new Dictionary<string, string>();

    foreach (var field in tagType.Fields)
    {
        if (field.Name == "value__")
        {
            continue;
        }

        if (field.HasCustomAttributes)
        {
            var derivedFrom = field.Name;

            var derivedFromAttribute = field.CustomAttributes.FirstOrDefault(attribute =>
                attribute.AttributeType.Resolve() == derivedFromAttributeType);
 ....
        }
    }

    return ...

There is an error during the compilation in Visual Studio or in pwsh via the command "./MSBuild.exe --restore "D:\source\projectName.csproj"" on the line "attribute.AttributeType.Resolve()"

Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
2> at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters) in C:\sources\cecil\Mono.Cecil\BaseAssemblyResolver.cs:line 172
2> at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name) in C:\sources\cecil\Mono.Cecil\DefaultAssemblyResolver.cs:line 33
2> at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) in C:\sources\cecil\Mono.Cecil\MetadataResolver.cs:line 111
2> at Mono.Cecil.TypeReference.Resolve() in C:\sources\cecil\Mono.Cecil\TypeReference.cs:line 278
2> at CodeGenerator.Parameters.Parser.ParametersXmlParser.Create() in D:\source\code-generators\sources\CodeGenerator.Parameters\Parser\ParametersXmlParser.cs:line 84

Compilation via the command "dotnet build "D:\source\projectName.csproj"" works smoothly.
The most interesting is that despite the error during the compilation the generator itself works after the build of the solution is finished with error, if I click "re-run" to generate the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant