Closed cezarypiatek closed 4 years ago
Indeed, loading dependencies is currently an issue. See #114 for tracking an attempt at fixing.
I've discovered that my generator assembly is loaded from the lib
directory instead of the tools. I have defined
GeneratorAssemblySearchPaths` in the following way:
<GeneratorAssemblySearchPaths Include="$(MSBuildThisFileDirectory)..\tools" />
How to force CodeGeneration.Roslyn
to load generators from the tools
directory?
Next observation: I think the problem is caused by this method https://github.com/AArnott/CodeGeneration.Roslyn/blob/0deb38f8c07461e44077e606dba619552e1c1018/src/CodeGeneration.Roslyn.Engine/CompilationGenerator.cs#L318
Because the generator assembly is searched in the first place in ReferencePath
instead of GeneratorAssemblySearchPaths
.
The problem occurs when the Attribute and Generator are in the same assembly.
Yes, so that'll be why for p2p (same solution) this works - that's because then you're referencing this project (and in turn assembly), so it becomes included in ReferencePath item.
I don't think there's an easy solution here, aside from separating attribute into another assembly.
PS Good investigation BTW.
For p2p approach, the GeneratorAssemblySearchPaths
variable is not set so changing the order of searching: first GeneratorAssemblySearchPaths
then ReferencePath
should fix the issue without any negative side effects.
I'm running into similar issues.
I'm writing a generator that depends on Microsoft.Data.SqlClient
.
I've combined the attributes and generators into the same assembly for simplicity.
If my lib is written against .net standard then I get these load exceptions.
Also for some reason the generator able to connect to local databases.
This will be resolved via Plugin.Sdk. Tracked in #113
Hi, I create a generator using CodeGeneration.Roslyn. Everything works when I'm using it in the same solution where the generator is defined. However, when I pack everything into a NuGet package and I try to use it in another project it fails. I'm getting the following exceptions:
I verified and the
Microsoft.CodeAnalysis.Workspaces
assembly with the expected version is present in thetools
folder inside the nuget package. It looks like a problem with loading generator dependencies.Update: My project is available here https://github.com/cezarypiatek/MappingGenerator/tree/feature/on_build_code_generation
The generator is defined in
OnBuildGenerator
project. Nuget should be generated automatically on build.