I'm trying to figure out the proper usage of generating Nuget packages via MSBuild /t:Pack
that would use a nuspec file containing the dollar tokens.
What I've done is:
- I defined a
<NuspecFile>
in my csproj file - I provided a basic nuspec file
- I attempted to execute
msbuild /t:Pack /p:Configuration=Release
It works fine and successfully applies the data provided in the nuspec file. Now when I update the nuspec with
<version>$version$</version>
I get the following
C:\Program Files\dotnet\sdk\2.2.103\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(202,5): error : An error occured while trying to parse the value '' of property 'version' in the manifest file. [C:\Users\patryk\source\repos\NuspecTokenReplacement\NuspecTokenReplacement\NuspecTokenReplacement.csproj]
C:\Program Files\dotnet\sdk\2.2.103\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(202,5): error : Value cannot be null or an empty string. [C:\Users\patryk\source\repos\NuspecTokenReplacement\NuspecTokenReplacement\NuspecTokenReplacement.csproj]
C:\Program Files\dotnet\sdk\2.2.103\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(202,5): error : Parameter name: value [C:\Users\patryk\source\repos\NuspecTokenReplacement\NuspecTokenReplacement\NuspecTokenReplacement.csproj]
The changes are available in the following repo: https://github.com/patrykbuzowicz/dotnet-msbuild-pack-nuspectokenreplacement
My question is: is it even possible to use the tokens in .nuspec files with the msbuild approach?
I know an alternative approach would be just to drop the .nuspec file and define the metadata in my .csproj file. This question is focused on the nuspec approach though.
Side question: does msbuild /t:Pack
work with the old style .csproj files, i.e. these before <Project Sdk="Microsoft.NET.Sdk">
? I'm getting Invalid target framework for the file ...
error when executing msbuild /t:Pack
on such an old .csproj.
And seems to be "fixed" after I manually add <TargetFramework>
to it (despite having <TargetFrameworkVersion>
) but that doesn't feel like a good way to go