-
Hi roslyn community, I build currently a bigger solution in a mono repo style, quite sucessfull. That means also we use a lot of project references instead of using nuget packages. The problem that I'm currently facing is the following project structure:
I let Project A reference my generator project with the following code: <ProjectReference Include="projectb.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="True"/> And Project C referenz Project A with: <ProjectReference Include="projecta.csproj" IncludeAssets="all" PrivateAssets="all"/> The question is: How can I use my generator (Project B) in Project C with just the package reference to Project A? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Well, I'll start by saying that I don't understand your project structure here. You have A referencing C, and C referencing A. That cannot work; you cannot have circular references like this, regardless of whether one is an analyzer. Can you clarify what reference structure you would like to have? Diagrams work well for this type of discussion. |
Beta Was this translation helpful? Give feedback.
-
So I kinda find a solution / workaround for me. Maybe it helps someone else. What I do right now is the following: Pack your generatorEdit your Property group in your csproj of the generator like the following: <TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<NoWarn>NU5128</NoWarn>
<LangVersion>8.0</LangVersion>
<Nullable>disable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<IsRoslynComponent>true</IsRoslynComponent>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <!-- Generates a package at build -->
<IncludeBuildOutput>false</IncludeBuildOutput> <!-- Do not include the generator as a lib dependency --> The lines about Add the generator DLL to the package
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup> This will add the generator to the nuget path Move the nuget package to your solution rootFor easy handling of the generators in your monorepo style solution you should move your nuget packages to the solution root. <Target Name="CopyPackage" AfterTargets="Pack">
<Copy SourceFiles="$(OutputPath)..\$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$(GitRootDirectory)/packages/" />
</Target> This will copy your nuget packages to the root of your repository into the packages folder following the .NET project structure
Add a nuget config<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<!--Paths for generators packages, that is needed to get reference trees for generators.-->
<add key="YourCompany.Nuget.Packages" value="./packages" />
</packageSources>
</configuration> This Nuget config will add your solution folder as a source of Nuget packages. So your generators can be found Add the generator as package refIn your project A you can now add the generator as package reference like that: <PackageReference Include="ProjectB" Version="1.0.0" /> Build orderThe last step is to adjust the build order. So project A always requires that Project B was build. cleanup Nuget cache folders
That is currently as far as I see only manual possible. Didn't found a good solution for it that runs stable ConclusionThat's not an easy way but it looks for now like the only solution. Thanks @333fred for the help :) |
Beta Was this translation helpful? Give feedback.
So I kinda find a solution / workaround for me. Maybe it helps someone else.
What I do right now is the following:
Pack your generator
Edit your Property group in your csproj of the generator like the following:
The…