I have an sln file which contains multiple csproj. We have a CI/CD pipeline (yml file) where I have to mention all (csproj)projects for which I want to push nugets to repository. Pipeline basically picks those csproj and then run dotnet pack
command with output set in a given directory. After which it run dotnet push
for all nuget pkgs in that directory.
I added all my csproj in that yml file. I used to only modify the versions in csproj where I made changes. Build pipeline used call dotnet pack and dotnet push on all the csproj - so the projects where I have not made any changes used to get overridden in repository with same version. Life was good for me.
Now repository team decided that they will make the nugets immutable. Which means I can no longer push the same version of nuget to repo and if I try it will fail the build.
Now I have two options -
- I commented all csproj in yml file and Before every build I have to uncomment the csproj(s) which I want to publish to repositry
- Add build number as patch version for all csproj, so every time I run build it will produce a unique version. Which also means I will be pushing nugets which have no change with new version.
If dotnet pack
doesn't produce any package in output directory for projects which have not changed dotnet push will not push them and life will be good again.
My Question :
Can I put some logic in csproj, so when run dotnet pack
command it doesn't return any error and doesn't produce any package in output directory based on if version in csproj is updated.
CodePudding user response:
You could parametrize your pipeline, and run the dotnet push command for each project conditionally. Or apply the —skip-duplicate argument all projects docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push