问题描述
我知道,自 msbuild 15(与 2017 年相比)发布以来,NuGet 现已完全集成到 MSBuild 中.
我有一个 nuspec 文件,其中定义了包属性的变量,例如:
<元数据><id>$id$</id><版本>$版本$</版本><作者>$authors$</authors>...</元数据>
nuspec 文件位于项目的同一文件夹中.
使用 nuget 工具创建包时,它工作正常.
nuget 包
使用 msbuild v15 时,会引发异常.
运行命令:
msbuild -version
<块引用>
适用于 .NET Framework 的 Microsoft (R) Build Engine 版本 15.8.168+ga8fba1ebd715.8.168.64424
msbuild/t:pack/p:configuration=release/p:NuspecFile=mylib.nuspec
引发异常:
<块引用>C:Program Filesdotnetsdk2.1.402SdksNuGet.Build.Tasks.PackuildNuGet.Build.Tasks.Pack.targets(199,5):错误:值不能为空或空字符串.
奇怪的是dotnet sdk 2.1.402版本引发了异常.
我尝试使用 vs2017 安装 msbuild 及其路径,但它也引发了相同的异常.
当我用它的值替换变量时,msbuild 工作正常.
问题
这是 msbuild 版本 15.8.168.64424 中的错误还是我遗漏了什么?
也就是说,msbuild 能否支持使用包的元数据变量?
正如评论中提到的,您不再需要 Nuspec 文件,因为大多数方面都可以通过 csproj 文件中的属性或项目的附加元数据来控制(例如,如果您需要其他内容).
如果出于某种原因确实需要 nuspec 文件,则需要自己提供用于替换的变量.您可以在 csproj 文件中的目标中执行此操作,如下所示:
<目标名称="SetNuspecProperties" BeforeTargets="GenerateNuspec"><属性组><NuspecProperties>$(NuspecProperties);id=$(AssemblyName)</NuspecProperties><NuspecProperties>$(NuspecProperties);config=$(Configuration)</NuspecProperties><NuspecProperties>$(NuspecProperties);version=$(PackageVersion)</NuspecProperties><NuspecProperties>$(NuspecProperties);description=$(Description)</NuspecProperties><NuspecProperties>$(NuspecProperties);authors=$(Authors)</NuspecProperties></属性组></目标>
I know Since the release of msbuild 15 (vs 2017) that NuGet is now fully integrated into MSBuild.
I have a nuspec file with defining variables of package properties like:
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$authors$</authors>
...
</metadata>
The nuspec file is located in the same folder of the project.
When using nuget tool to create the package , it works fine.
nuget pack
When using msbuild v15, it raise an exception.
run the command:
msbuild -version
Microsoft (R) Build Engine version 15.8.168+ga8fba1ebd7 for .NET Framework 15.8.168.64424
msbuild /t:pack /p:configuration=release /p:NuspecFile=mylib.nuspec
raise exception:
C:Program Filesdotnetsdk2.1.402SdksNuGet.Build.Tasks.PackuildNuGet.Build.Tasks.Pack.targets(199,5): error : Value cannot be null or an empty string.
The strange is that dotnet sdk version 2.1.402 raises the exception.
I tried msbuild installed with vs2017 with its path and also it raises the same exception.
When i substitute the variables with its values, msbuild is working fine.
The question
Is this a bug in msbuild version 15.8.168.64424 or i missed something ?
In other words, Can msbuild support using the metadata variables of the package?.
As has been mentioned in the comments, you no longer need a Nuspec file as most aspects can be controlled via properties in the csproj file or additional metadata on items (e.g. if you need additional content).
If you do need a nuspec file for some reason, you need to provide the variables for substitution yourself. You can do this in a target inside the csproj file like this:
<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<NuspecProperties>$(NuspecProperties);id=$(AssemblyName)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);config=$(Configuration)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);version=$(PackageVersion)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);description=$(Description)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);authors=$(Authors)</NuspecProperties>
</PropertyGroup>
</Target>
这篇关于Msbuild v15 无法解析 nuspec 文件元数据的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!