SergeyTeplyakov / ErrorProne.NET

Set of roslyn-based analyzers for catching common C# errors (inspired by Google's error-prone)
MIT License
886 stars 42 forks source link

Building a nuget package from the source code #259

Open nuller1joe opened 1 year ago

nuller1joe commented 1 year ago

Hey

I'm having some trouble getting the nuget package working building it myself.

After building the latest source code with msbuild /p:PublicRelease=true

I get a nuget package in ./ErrorProne.NET.StructAnalyzers.CodeFixes/bin/debug/ErrorProne.NET.Structs.0.5.0-beta6.nupkg (likewise for Core Analyzers)

Adding the package to my local nuget repo: nuget add './ErrorProne.NET.StructAnalyzers.CodeFixes/bin/debug/ErrorProne.NET.Structs.0.5.0-beta6.nupkg' -Source 'c:/store' and adding the local store to my project NuGet.config allows me to see and install the package.

After installing the locally created nuget package, no warnings or errors is appearing.

If I use the official nuget repo to install 0.4.0-beta.1 I get all the expected warnings. However, if I build the commit for the release of 0.4.0, it doesn't work either. Same with 0.3.0.

Do I need to set any flags to get the local built analyzer working?

munik commented 9 months ago

I'm also running into the same issue and unable to get a working NuGet package output from the build.

nuller1joe commented 9 months ago

The solution I came up with that worked for me:

Following is based on the git commit: f6787c08d76ca761eee3d103f43c4289bbb4d3cb

The newest official nuget package (v.0.4.0-beta.1) did not work correctly.
Neither did newest commit (f6787c08d76ca761eee3d103f43c4289bbb4d3cb) which should be version 0.5.0

I have done some slight changes to get it working.

1) In order to run this project at all, visual studio needs to be installed (it is a bit sensitive to which version of VS I think). I used Visual Studio Enterprise 2022 v17.4.1
2) There exist two patches that is my changes upon official commit f6787c08d76ca761eee3d103f43c4289bbb4d3cb
    - ./patchBasic.diff which only changes the minimum to actually be able to open and build the project
    - ./patchExtende2d.diff which contains the code changes to not throw when analyzing. Furthermore FxCopAnalyzer was replaced with DotnetAnalyzwer. A range of nuget packages was updated
3) To build (Navigate to ./src):
    - Run: dotnet restore
    - Run: msbuild /p:PublicRelease=true
4) Install newly built nuget package:
    - .\nuget.exe add .\ErrorProne.NET.StructAnalyzers.CodeFixes\bin\Debug\ErrorProne.NET.Structs.0.5.0-beta.6.nupkg -Source ..\..
    (where source is the project you want the nuget package added to)
    - After running the command go to source path and find 'errorprone.net.structs\0.5.0-beta.6'
    - Open 'errorprone.net.structs.0.5.0-beta.6.nupkg' as a ZIP file, and extract (and replace) all files in 'errorprone.net.structs\0.5.0-beta.6'
5) Same can be done for the CoreAnalyzer if needed

patchExtended2.diff.txt patchBasic.diff.txt

I hope this helps you

munik commented 9 months ago

@nuller1joe thanks for that, but I need to be able to run a build that produces working .nupkg files. As it is, I get an error about RuntimeContracts.dll missing when I run the analyzer in the .nupkg files that are currently generated. It looks like the very last commit (3aebd274d1d0ebcd36355fa113bf26ab5abcf862) commented out the <ILRepack ... /> directive which I'm guessing is not bundling RuntimeContracts.dll like it should be. But I'm not sure.

@SergeyTeplyakov can you provide any input here?

munik commented 9 months ago

@mkerkelpgr I'm not sure, but possibly your change in 3aebd27 resulted in the NuGet packages not being created. I don't understand the build infra for this project -- do you know what it was supposed to do and/or are you able to create working NuGet packages?

mkerkelpgr commented 9 months ago

@SergeyTeplyakov @munik I am awaiting to hear from Sergey on that issue as well.