简体   繁体   English

使用VSTS和Nuget Pack自动添加nuget依赖项

[英]Automatically add nuget dependencies using VSTS and Nuget Pack

I am using Visual Studio Team Services to run builds for a library that I publish as a Nuget package. 我正在使用Visual Studio Team Services为作为Nuget包发布的库运行构建。

The project contains a nuspec file which specifies the name, description, project url and other static info. 该项目包含一个nuspec文件,该文件指定了名称,描述,项目url和其他静态信息。

This nuspec file is referenced on the Nuget pack build action in VSTS VSTS中的Nuget包构建操作引用了此nuspec文件

在此处输入图片说明

I would like to include the info about dependencies as well, however, I do not want to manage that manually in the nuspec XML (error prone and time consuming). 我也想包括有关依赖项的信息,但是,我不想在nuspec XML中手动进行管理(容易出错且耗时)。

The nuspec file does not contain the element, so I hoped VSTS NuGet pack action would include them automatically. nuspec文件不包含该元素,因此我希望VSTS NuGet pack操作将自动包括它们。

Is there any way to achieve that? 有什么办法可以实现?

You can use the new "SDK style" csproj format to move NuGet concerns into a single csproj file that lets you specify dependencies and static metadata in one place. 您可以使用新的“ SDK样式” csproj格式将NuGet关注点移动到单个csproj文件中,该文件可让您在一个位置指定依赖项和静态元数据。

Best to start out creating a .NET Standard Library and change the <TargetFramework> property from netstandard2.0 to the framework you targeted before - eg net452 . 最好从创建.NET标准库开始,然后将<TargetFramework>属性从netstandard2.0为之前指定的框架-例如net452 (Or select an appropriate .NET Standard version) (或选择适当的.NET Standard版本)

This project type can be packed using msbuild /t:Pack or dotnet pack 可以使用msbuild /t:Packdotnet pack打包此项目类型

When you add project or NuGet package references, these will automatically turn into dependencies during packing and if you reference packages via wildcard ( 1.2.* ), the package will depend on the version resolved during restore. 添加项目或NuGet程序包引用时,这些将在打包过程中自动转换为依赖项,如果您通过通配符( 1.2.* )引用程序包,则该程序包将取决于还原过程中解析的版本。 VS offers a dialog to edit package metadata for this project type in the project properties. VS提供了一个对话框,可在项目属性中编辑此项目类型的程序包元数据。

Apparently, quite a simple solution exists. 显然,存在一个非常简单的解决方案。
You can set your VSTS Nuget pack task to use the csproj file (not the nuspec), however it will still access the nuscpec to get the metadata. 您可以将VSTS Nuget pack任务设置为使用csproj文件(而不是nuspec),但是它仍将访问nuscpec以获取元数据。 See the logs below: 请参阅以下日志:

在此处输入图片说明

To reiterate, instead of setting the pattern for the nuspec file in the build task in VSTS, set the path to the csproj file. 重申一下,而不是在VSTS的构建任务中为nuspec文件设置模式,而是将路径设置为csproj文件。

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

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