Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

like image 317
M.Hassan Avatar asked Oct 18 '18 19:10

M.Hassan


1 Answers

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>
like image 77
Martin Ullrich Avatar answered Nov 15 '22 15:11

Martin Ullrich