choco icon indicating copy to clipboard operation
choco copied to clipboard

new - Token replacement with in nuspec should more closely match nuget

Open asears opened this issue 5 years ago • 3 comments

What You Are Seeing?

Within the scaffolded .nuspec template generated by a command such as choco new -n bob, there are some tokens for replacement. Since choco uses nuget pack, I was able to successfully replace the default token REPLACE with $version$ and remove the need to edit/substitute the file.

What is Expected?

  • Editing or token-substitution should be handled by the build tooling.
  • Tokens should be named for ease of replacement
  • Tokens should follow nuspec standards
  • Command-line should be used for all steps in pipeline

Should the default choco new command scaffold a valid nuspec with proper tokens, and verify on pack that all tokens are set? This might require a feature flag to ensure backwards compatibility in builds and updates to tutorials and help.

https://docs.microsoft.com/en-us/nuget/reference/nuspec#replacement-tokens

There is some variations between nuspec and csproj behavior, not sure if fixed. https://github.com/NuGet/Home/issues/1795

I got here from following the tutorial https://chocolatey.org/courses/creating-chocolatey-packages/nuget-packages-and-nuspec

How Did You Get This To Happen? (Steps to Reproduce)

choco new -n bob
choco pack -build .\bob\bob.nuspec --outputdirectory .\build --version=0.0.1-alpha

Output Log

Chocolatey v0.10.15
'__REPLACE__' is not a valid version string.
Parameter name: version
Full Log Output

PLACE LOG CONTENT HERE - WE NEED _ALL_ DETAILED OUTPUT BASED ON THE ABOVE TO BE ABLE TO PROVIDE SUPPORT (YOU WILL FIND THAT IN THE $env:ChocolateyInstall\logs\chocolatey.log between the `=====`)

asears avatar Aug 13 '20 11:08 asears

As long as we have the understanding that while Chocolatey builds on NuGet, they are not one and the same and there are likely going to be differences between how the two behave, I think this could be a good change indeed.

ferventcoder avatar Aug 22 '20 19:08 ferventcoder

Updated the title, I think that makes sense. Thoughts?

ferventcoder avatar Aug 22 '20 19:08 ferventcoder

Looking into this a little bit, using a nuspec with the following:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <id>bob</id>
    <version>$version$</version>
    <title>bob (Install)</title>
    <authors>__REPLACE_AUTHORS_OF_SOFTWARE_COMMA_SEPARATED__</authors>
    <tags>bob SPACE_SEPARATED</tags>
    <summary>__REPLACE__</summary>
    <description>__REPLACE__MarkDown_Okay </description>
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>

If you run choco pack you get the following output:

The replacement token 'version' has no value.

And using the following nuspec:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <id>bob</id>
    <version>__REPLACE__</version>
    <title>bob (Install)</title>
    <authors>__REPLACE_AUTHORS_OF_SOFTWARE_COMMA_SEPARATED__</authors>
    <tags>bob SPACE_SEPARATED</tags>
    <summary>__REPLACE__</summary>
    <description>__REPLACE__MarkDown_Okay </description>
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>

And then you run choco pack you get the following output:

'__REPLACE__' is not a valid version string.
Parameter name: version

So in both of these places, the output is similar.

The difference comes in when you run the command:

choco pack --version 1.2.3

For the first nuspec file, a file called bob.1.2.3.nupkg is created. However, with the second nuspec file, you once again get the output:

'__REPLACE__' is not a valid version string.
Parameter name: version

We should have better handling in this area, so that either one of two things is changed:

  1. The default template for a nuspec is changed to use the $version$ nomenclature
  2. If --version is passed in, the value that is currently contained within the version XML element is replaced, regardless of whether it is currently a valid version number or not.

gep13 avatar Dec 20 '22 13:12 gep13