如果CSPROJ没有更改,是否可能不输出Nuget软件包?

发布于 2025-01-18 08:33:54 字数 814 浏览 3 评论 0 原文

我有一个 sln 文件,其中包含多个 csproj。我们有一个 CI/CD 管道(yml 文件),我必须在其中提及我想要将 nuget 推送到存储库的所有 (csproj) 项目。管道基本上选择这些 csproj,然后运行 ​​dotnet pack 命令,并在给定目录中设置输出。之后,它对该目录中的所有 nuget pkg 运行 dotnet push

我将所有 csproj 添加到该 yml 文件中。我以前只修改csproj中我进行更改的版本。构建管道使用在所有 csproj 上调用 dotnet pack 和 dotnet push - 因此我没有进行任何更改的项目用于在具有相同版本的存储库中被覆盖。生活对我来说是美好的。

现在,存储库团队决定让 nuget 变得不可变。这意味着我无法再将相同版本的 nuget 推送到存储库,如果我尝试,构建将会失败。

现在我有两个选择 -

  1. 我在 yml 文件中注释了所有 csproj,并且在每次构建之前我必须取消注释我想要发布到存储库的 csproj
  2. 添加构建号作为所有 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 -

  1. 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
  2. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

究竟谁懂我的在乎 2025-01-25 08:33:54

您可以对管道进行参数,并为每个项目运行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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文