简体   繁体   English

有条件地指定nuget软件包版本

[英]specify nuget package version conditionally

Let's say I am working on a Feature (C# project) that is toggled off, ie not ready to be released. 假设我正在处理一个功能(C#项目),该功能已关闭,即尚未准备好发布。

My project depends on a component via nuget, which is also something I maintain. 我的项目依赖于nuget的组件,这也是我维护的。

My feature requires changes to the component, as well as my consuming project. 我的功能需要更改组件以及消耗的项目。

I need to make intermediate releases, and I prefer not to branch. 我需要发布中间版本,并且我不希望分支。

In my project, I can toggle the Feature off and ship. 在我的项目中,我可以关闭并发送功能。 Question is : how do I use nuget in a feature toggled project, such that if Feature is off, I use version X of component, and version X+1 when the feature is on. 问题是:如何在功能切换的项目中使用nuget,例如,如果功能已关闭,则我使用组件的X版本,而功能打开时使用X + 1版本。

  • I could not find any way of adding conditions to packages.config 我找不到任何将条件添加到packages.config

The only thing I can think of is, use a different feed for non-release environment, but that could lead to other logistical issues. 我唯一能想到的是,对非发布环境使用不同的提要,但这可能会导致其他后勤问题。

Edit: 编辑:

My builds run on a CI server, so I need to be able to script it somehow. 我的构建在CI服务器上运行,因此我需要能够以某种方式编写脚本。

If you control the NuGet source then you can use the Pre-Release functionality . 如果您控制NuGet源,则可以使用Pre-Release功能

Essentially you version control your Nuget packages by suffixing them with -alpha or -beta and then in Visual Studio you tick the check box for "Include prelease" in you NuGet package feed. 本质上,您可以通过在Nuget软件包后缀-alpha-beta对Nuget软件包进行版本控制,然后在Visual Studio中选中NuGet软件包供稿中“包括prelease”复选框。

For using a switch on a build server I suggest you look at using MSBuild / MSBuild Community Tasks / MSBuild Extension pack. 对于在构建服务器上使用开关,建议您使用MSBuild / MSBuild社区任务/ MSBuild扩展包。

You can run a build step using MSBuild that can examine a config file and amend a .nuspec file. 您可以使用MSBuild运行构建步骤,该步骤可以检查配置文件并修改.nuspec文件。 I don't have the source to hand as it was a while ago, but it is possible to use xml / msbuild to parse an xml file and apply changes to it. 我没有前一阵子的手头,但是可以使用xml / msbuild来解析xml文件并对其进行更改。 IIRC a big "gotcha" was that you need to specifiy the .nusepc namespace IIRC的一个大“陷阱”是您需要指定.nusepc命名空间

<package xmlns="http://schemas.microsoft.com/packaging/2016/06/nuspec.xsd">

when you are parsing the nuspec file.It should then be possible to target the <dependencies> element and suffix all the dependecies with the pre-release tag. 当您解析nuspec文件时,应该可以将<dependencies>元素作为目标,并使用pre-release标签为所有依赖项添加后缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM