简体   繁体   English

Msbuild v15 无法解析nuspec文件的元数据变量

[英]Msbuild v15 can't resolve the variables of metadata of nuspec file

I know Since the release of msbuild 15 (vs 2017) that NuGet is now fully integrated into MSBuild.我知道自从 msbuild 15(与 2017 年相比)发布以来,NuGet 现在已完全集成到 MSBuild 中。

I have a nuspec file with defining variables of package properties like:我有一个 nuspec 文件,其中定义了包属性的变量,例如:

    <metadata>
        <id>$id$</id>
        <version>$version$</version>  
        <authors>$authors$</authors>
    ...
    </metadata> 

The nuspec file is located in the same folder of the project. nuspec 文件位于项目的同一文件夹中。

When using nuget tool to create the package , it works fine.使用 nuget 工具创建包时,它工作正常。

    nuget pack   

When using msbuild v15, it raise an exception.使用 msbuild v15 时,会引发异常。

run the command:运行命令:

    msbuild -version

Microsoft (R) Build Engine version 15.8.168+ga8fba1ebd7 for .NET Framework 15.8.168.64424适用于 .NET Framework 15.8.168.64424 的 Microsoft (R) 构建引擎版本 15.8.168+ga8fba1ebd7

    msbuild  /t:pack /p:configuration=release    /p:NuspecFile=mylib.nuspec

raise exception:引发异常:

C:\\Program Files\\dotnet\\sdk\\2.1.402\\Sdks\\NuGet.Build.Tasks.Pack\\build\\NuGet.Build.Tasks.Pack.targets(199,5): error : Value cannot be null or an empty string. C:\\Program Files\\dotnet\\sdk\\2.1.402\\Sdks\\NuGet.Build.Tasks.Pack\\build\\NuGet.Build.Tasks.Pack.targets(199,5): 错误:值不能为 null 或为空细绳。

The strange is that dotnet sdk version 2.1.402 raises the exception.奇怪的是 dotnet sdk 版本 2.1.402 引发了异常。

I tried msbuild installed with vs2017 with its path and also it raises the same exception.我尝试使用 vs2017 安装了 msbuild 及其路径,它也引发了相同的异常。

When i substitute the variables with its values, msbuild is working fine.当我用它的值替换变量时,msbuild 工作正常。

The question问题

Is this a bug in msbuild version 15.8.168.64424 or i missed something ?这是 msbuild 版本 15.8.168.64424 中的错误还是我错过了什么?

In other words, Can msbuild support using the metadata variables of the package?.换句话说,msbuild 是否支持使用包的元数据变量?。

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 (eg if you need additional content).正如评论中提到的,您不再需要 Nuspec 文件,因为大多数方面都可以通过 csproj 文件中的属性或项目的其他元数据进行控制(例如,如果您需要其他内容)。

If you do need a nuspec file for some reason, you need to provide the variables for substitution yourself.如果出于某种原因确实需要 nuspec 文件,则需要自己提供用于替换的变量。 You can do this in a target inside the csproj file like this:您可以在 csproj 文件内的目标中执行此操作,如下所示:

<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>

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

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