C
C#2w ago
AnnaSasDev

Roslyn not finding a referenced package

Hey there Over the past months I've really fallen in love with writing my own Roslyn code generators. My Discriminated Unions library heavily relies on this, and because I have noticed that some of my generators share the same basic code, I wanted to write a simple library I could use in my various projects : https://github.com/code-of-chaos/cs-code_of_chaos-generator_tools The issue now is that I try and use the uploaded nuget package in the consumer Roslyn generator found here: https://github.com/AterraEngine/unions-cs/blob/core/src/AterraEngine.Unions.Generators/AterraEngine.Unions.Generators.csproj Within the IDE (rider) everything seems to be fine in the generator's code as it discovers all the types within the package and I'm able to use them when I'm writing code, but whenever I try and use the generator no code appears and I get the error :
System.IO.FileNotFoundException: Could not load file or assembly 'CodeOfChaos.GeneratorTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'CodeOfChaos.GeneratorTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null'
at AterraEngine.Unions.Generators.UnionGenerator.GenerateUnionCode(UnionObject unionObject)
at AterraEngine.Unions.Generators.UnionGenerator.GenerateSources(SourceProductionContext context, ValueTuple`2 source) in C:\Dev\unions-cs\src\AterraEngine.Unions.Generators\UnionGenerator.cs:line 163
at Microsoft.CodeAnalysis.UserFunctionExtensions.<>c__DisplayClass3_0`2.<WrapUserAction>b__0(TInput1 input1, TInput2 input2, CancellationToken token)
System.IO.FileNotFoundException: Could not load file or assembly 'CodeOfChaos.GeneratorTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'CodeOfChaos.GeneratorTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null'
at AterraEngine.Unions.Generators.UnionGenerator.GenerateUnionCode(UnionObject unionObject)
at AterraEngine.Unions.Generators.UnionGenerator.GenerateSources(SourceProductionContext context, ValueTuple`2 source) in C:\Dev\unions-cs\src\AterraEngine.Unions.Generators\UnionGenerator.cs:line 163
at Microsoft.CodeAnalysis.UserFunctionExtensions.<>c__DisplayClass3_0`2.<WrapUserAction>b__0(TInput1 input1, TInput2 input2, CancellationToken token)
I've been stuck at this for a few hours now, and I'm lost at where I've created some issue
GitHub
GitHub - code-of-chaos/cs-code_of_chaos-generator_tools: A set of t...
A set of tools to help you create code generators more easily - code-of-chaos/cs-code_of_chaos-generator_tools
GitHub
unions-cs/src/AterraEngine.Unions.Generators/AterraEngine.Unions.Ge...
A Union Library for DotNet. Contribute to AterraEngine/unions-cs development by creating an account on GitHub.
1 Reply
AnnaSasDev
AnnaSasDevOP2w ago
I haven't created a new latest nuget package for AterraEngine.Unions.Generators yet as the code isn't working. Within the project there is a Sample project AterraEngine.Unions.Generators.Sample which when I try and build outputs:
1>CSC: Warning CS8785 : Generator 'UnionGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'CodeOfChaos.GeneratorTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.'.
1>CSC: Warning CS8785 : Generator 'UnionGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'CodeOfChaos.GeneratorTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.'.
AterraEngine.Unions.Generators is on the latest uploaded version of CodeOfChaos.GeneratorTools which is 1.1.0 csproj file of AterraEngine.Unions.Generators : (had to split the file because of max message length)
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <!-- Generates a package at build -->
<IncludeBuildOutput>false</IncludeBuildOutput> <!-- Do not include the generator as a lib dependency -->
<IsDeveloperDependency>true</IsDeveloperDependency>
<DevelopmentDependency>true</DevelopmentDependency>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
<NoWarn>NU5128</NoWarn>

<!-- Package metadata -->
<PackageId>AterraEngine.Unions.Generators</PackageId>
<Version>3.5.0</Version>
<Authors>Anna Sas</Authors>
<Description>The Source Generator for AterraEngine.Unions</Description>
<PackageProjectUrl>https://github.com/AterraEngine/unions-cs/</PackageProjectUrl>
<PackageTags>discriminated unions;rosyln;generator</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<DebugType>embedded</DebugType>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <!-- Generates a package at build -->
<IncludeBuildOutput>false</IncludeBuildOutput> <!-- Do not include the generator as a lib dependency -->
<IsDeveloperDependency>true</IsDeveloperDependency>
<DevelopmentDependency>true</DevelopmentDependency>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
<NoWarn>NU5128</NoWarn>

<!-- Package metadata -->
<PackageId>AterraEngine.Unions.Generators</PackageId>
<Version>3.5.0</Version>
<Authors>Anna Sas</Authors>
<Description>The Source Generator for AterraEngine.Unions</Description>
<PackageProjectUrl>https://github.com/AterraEngine/unions-cs/</PackageProjectUrl>
<PackageTags>discriminated unions;rosyln;generator</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<DebugType>embedded</DebugType>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>
<!-- Include external files -->
<ItemGroup>
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<!-- Package dependencies -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all" />
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.1.0" Pack="true" GeneratePathProperty="true" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>

</Project>
<!-- Include external files -->
<ItemGroup>
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<!-- Package dependencies -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all" />
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.1.0" Pack="true" GeneratePathProperty="true" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>

</Project>
csproj file of CodeOfChaos.GeneratorTools :
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>

<DevelopmentDependency>true</DevelopmentDependency>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>

<!-- Main package metadata -->
<PackageId>CodeOfChaos.GeneratorTools</PackageId>
<Version>1.1.0</Version>
<Authors>Anna Sas</Authors>
<Description>A library to help you create code generators more easily</Description>
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-generator_tools/</PackageProjectUrl>
<PackageTags>roslyn code-generator generator source-generator source</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<DebugType>embedded</DebugType>
<PackageLicenseFile Condition="'$(Configuration)' != 'Benchmark'">LICENSE</PackageLicenseFile>
<PackageReadmeFile Condition="'$(Configuration)' != 'Benchmark'">README.md</PackageReadmeFile>
<PackageIcon Condition="'$(Configuration)' != 'Benchmark'">icon.png</PackageIcon>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>

<DevelopmentDependency>true</DevelopmentDependency>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>

<!-- Main package metadata -->
<PackageId>CodeOfChaos.GeneratorTools</PackageId>
<Version>1.1.0</Version>
<Authors>Anna Sas</Authors>
<Description>A library to help you create code generators more easily</Description>
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-generator_tools/</PackageProjectUrl>
<PackageTags>roslyn code-generator generator source-generator source</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<DebugType>embedded</DebugType>
<PackageLicenseFile Condition="'$(Configuration)' != 'Benchmark'">LICENSE</PackageLicenseFile>
<PackageReadmeFile Condition="'$(Configuration)' != 'Benchmark'">README.md</PackageReadmeFile>
<PackageIcon Condition="'$(Configuration)' != 'Benchmark'">icon.png</PackageIcon>
</PropertyGroup>
<!-- Ensure important files are packaged correctly -->
<ItemGroup Condition="'$(Configuration)' != 'Benchmark'">
<None Include="$(SolutionDir)LICENSE" Pack="true" PackagePath="" Visible="false" />
<None Include="$(SolutionDir)README.md" Pack="true" PackagePath="" Visible="false" />
<None Include="$(SolutionDir)assets/icon.png" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<!-- Reference dependencies -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all" />
</ItemGroup>

</Project>
<!-- Ensure important files are packaged correctly -->
<ItemGroup Condition="'$(Configuration)' != 'Benchmark'">
<None Include="$(SolutionDir)LICENSE" Pack="true" PackagePath="" Visible="false" />
<None Include="$(SolutionDir)README.md" Pack="true" PackagePath="" Visible="false" />
<None Include="$(SolutionDir)assets/icon.png" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<!-- Reference dependencies -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all" />
</ItemGroup>

</Project>
... what the .. yeah that fixed it?!? I'm so confused why this works ... but okay right, I've learned something new today then ... Thanks so much!

Did you find this page helpful?