我有一个 sln 文件,其中包含多个 csproj。我们有一个 CI/CD 管道(yml 文件),我必须在其中提及我想要将 nuget 推送到存储库的所有 (csproj) 项目。管道基本上选择这些 csproj,然后运行 dotnet pack
命令,并在给定目录中设置输出。之后,它对该目录中的所有 nuget pkg 运行 dotnet push
。
我将所有 csproj 添加到该 yml 文件中。我以前只修改csproj中我进行更改的版本。构建管道使用在所有 csproj 上调用 dotnet pack 和 dotnet push - 因此我没有进行任何更改的项目用于在具有相同版本的存储库中被覆盖。生活对我来说是美好的。
现在,存储库团队决定让 nuget 变得不可变。这意味着我无法再将相同版本的 nuget 推送到存储库,如果我尝试,构建将会失败。
现在我有两个选择 -
- 我在 yml 文件中注释了所有 csproj,并且在每次构建之前我必须取消注释我想要发布到存储库的 csproj
- 添加构建号作为所有 csproj 的补丁版本,所以每次我运行构建它将产生一个独特的版本。这也意味着我将推送新版本中没有变化的 nugets。
如果 dotnet pack
没有在未更改的项目的输出目录中生成任何包,则 dotnet Push 将不会推送它们,生活将再次美好。
我的问题:
我可以在 csproj 中添加一些逻辑,这样当运行 dotnet pack 命令时,它不会返回任何错误,并且不会根据 csproj 中的版本是否更新而在输出目录中生成任何包。
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.
发布评论
评论(1)
您可以对管道进行参数,并为每个项目运行Dotnet推动命令。或应用-skip-deplicate参数所有项目learn.microsoft.com/en-us/dotnet/core/core/tools/dotnet-nuget-push
You could parametrize your pipeline, and run the dotnet push command for each project conditionally. Or apply the —skip-duplicate argument all projects learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push