How to create a local nuget package and use it in my another project? #75167
Replies: 2 comments 12 replies
-
I would start by looking in the nuget package and making sure that everything is where you expect it to be. On a side note, are you using Unity? Unless that's true, please don't use |
Beta Was this translation helpful? Give feedback.
-
I've put my code here and my nuget package is here |
Beta Was this translation helpful? Give feedback.
-
I have a source generator project called metricsFactoryTest which will generate some factory code:
Now I want to reference this project in my another project called 'MainProject'.
One easy way to do this is to add a ProjectReference in the MainProject and this works for me
<ProjectReference Include="..\MetricsFactoryTest\MetricsFactoryTest.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> -->
But I want to publish the metricsFactoryTest to nuget package in the future and want to test locally if this package can work.
So I create a nuget package based on this guide: https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md#package-a-generator-as-a-nuget-package
here is my metricsFactoryTest.csproj file
and then I create a package using 'dotnet pack' cmd to generate
MetricsFactoryTest.1.0.0.nupkg
After that I install this local package through visual studio in my MainProject:
Then a package reference is generated in my MainProject.csproj
<PackageReference Include="MetricsFactoryTest" Version="1.0.0" />
but thenMetricsFactoryTest will not work, I cannot see this analyzers in the visual studio and I cannot use the code generated.
if I switch back to project reference
<ProjectReference Include="..\MetricsFactoryTest\MetricsFactoryTest.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
the analyzer will show up again
So is there anything wrong with the my packaging steps? Not sure if I miss anything
Beta Was this translation helpful? Give feedback.
All reactions