Source generator - how to reference a project? #48746
Replies: 5 comments 6 replies
-
|
This has been asked before. But the accepted answered by @sharwell is not about project references, it is about package references. Take a look, maybe you can work something out. (I am having trouble having a project reference as well.) |
Beta Was this translation helpful? Give feedback.
-
|
I had the same problem but found a workaround. In SourceGeneratorSamples.csproj, replace with a reference to the built dll (your HintPath might need to be changed): Next, we need to make sure that the dll is always built before the generator is built:
I didn't get it to work to build under linux / linux docker container, though :-( |
Beta Was this translation helpful? Give feedback.
-
|
I have such generator project file and all is ok. I can use classes from UIEngine.Vue and UIEngine projects. My main project that uses generator My IDE |
Beta Was this translation helpful? Give feedback.
-
|
Now I have such problem in 16.9.0 - 16.9.2 versions of VS2019. But at the same time nuget reference works fine. I've added one of the assembly as project reference into the generator project. And sometimes I have But sometimes it works! What I do? Just comment/uncomment that code line in the Initialize method: I also noticed that I have exception when current directory is C:/Program Files. How ask VS2019 run generator in the project directory always? There was not in the 16.8.xx versions of VS2019. |
Beta Was this translation helpful? Give feedback.
-
|
I met the same problem and tried anything I could. Then my choice was just giving it up atm. This just need a proper fix. I hope the issue can be resolved at the time .NET 6 is released. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a source generator project (SourceGeneratorSamples.csproj) from where I want to reference another project (MyLib.csproj) in the same solution. This lib is needed to generate the source text AND is also referenced inside that generated code.
Here the SourceGeneratorSamples.csproj:
When I try to use this generator in a simple console program (GeneratedDemo) I get a warning and an error.
CSC : warning CS8785: Generator 'ModelGenerator' 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 'MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.'
C:\Users\xxxx\source\repos\SourceGenerators\GeneratedDemo\Program.cs(5,7): error CS0246: The type or namespace name 'ModelGenerated' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\xxxx\source\repos\SourceGenerators\GeneratedDemo\GeneratedDemo.csproj]
and here the GeneratedDemo.csproj:
I tried everything - PrivateAssets, GeneratePackageOnBuild, IncludeBuildOutput, DevelopmentDependency, GeneratePathProperty, TargetPathWithTargetPlatformMoniker . . . this is so painful
What's wrong?
Beta Was this translation helpful? Give feedback.
All reactions