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

落花浮王杯 提交于 2019-12-19 07:53:20

问题


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

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


回答1:


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>


来源:https://stackoverflow.com/questions/52881557/msbuild-v15-cant-resolve-the-variables-of-metadata-of-nuspec-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!