Closed augustoproiete closed 3 years ago
What's odd is that I have been adding version information to my nuget packages during the "pack" step like so:
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
IncludeSource = false,
IncludeSymbols = true,
NoBuild = true,
NoRestore = true,
NoDependencies = true,
OutputDirectory = outputDir,
SymbolPackageFormat = "snupkg",
ArgumentCustomization = (args) =>
{
return args
.Append("/p:PackageReleaseNotes=\"{0}\"", releaseNotesUrl)
.Append("/p:Version={0}", versionInfo.LegacySemVerPadded)
.Append("/p:AssemblyVersion={0}", versionInfo.MajorMinorPatch)
.Append("/p:FileVersion={0}", versionInfo.MajorMinorPatch)
.Append("/p:AssemblyInformationalVersion={0}", versionInfo.InformationalVersion);
}
};
DotNetCorePack(sourceProject, settings);
and the result is exactly as I expect:
See here
Maybe we can set the version information during build or pack steps interchangeably???
Interesting. Have you tried removing these lines from the build.cake
file to see if it makes any difference?
You have NoBuild = true
so that should prevent dotnet pack
from calling dotnet build
(which is the real "consumer" of these assembly properties)... AFAIK dotnet pack
itself doesn't make any changes to assemblies.
Thus, my first guess is that something else in your build process (SourceLink?) is setting the assembly version, file version, etc. for you and these properties in the build script are being ignored.
My second guess is that something is causing NoBuild = true
to be ignored, and your project is being built twice, once when you call DotNetCoreBuild
and again when you call DotNetCorePack
. Might be easy to check with diagnostic verbosity turned on.
Maybe we can set the version information during build or pack steps interchangeably???
Yes, if we add to DotNetCoreMSBuildSettings
, it will be available for build
, pack
, publish
, etc. all the commands that can end up calling MSBuild.
Usage could be something similar to:
DotNetCorePack("./Project.csproj", new DotNetCoreBuildSettings
{
MSBuildSettings = new DotNetCoreMSBuildSettings()
.SetVersion(versionInfo.LegacySemVerPadded)
.SetAssemblyVersion(versionInfo.MajorMinorPatch)
.SetFileVersion(versionInfo.MajorMinorPatch)
.SetInformationalVersion(versionInfo.InformationalVersion)
});
// or
var msBuildSettings = new DotNetCoreMSBuildSettings
{
Version = versionInfo.LegacySemVerPadded,
AssemblyVersion = versionInfo.MajorMinorPatch,
FileVersion = versionInfo.MajorMinorPatch,
InformationalVersion = versionInfo.InformationalVersion,
};
DotNetCorePack("./Project.csproj", new DotNetCoreBuildSettings
{
MSBuildSettings = msBuildSettings,
});
But, of course, the same principle apply i.e. If you set these version properties in DotNetCorePack
you can't also set NoBuild = true
... You need to let dotnet pack
call dotnet build
on your behalf to make the updates to the assemblies.
Final list of properties to be added:
MSBuild Settings Property | MSBuild Settings Extension | Description |
---|---|---|
Version |
SetVersion |
Default version e.g. 1.2.3-pre |
VersionPrefix |
SetVersionPrefix |
Version prefix e.g. 1.2.3 |
VersionSuffix |
SetVersionSuffix |
Version suffix e.g. pre |
FileVersion |
SetFileVersion |
File version e.g. 1.2.3.0 |
AssemblyVersion |
SetAssemblyVersion |
Assembly version e.g. 1.0.0.0 |
InformationalVersion |
SetInformationalVersion |
Informational version e.g. 1.2.3-pre+7ad03d0 |
PackageVersion |
SetPackageVersion |
NuGet package version e.g. 1.2.3-pre |
PackageReleaseNotes |
SetPackageReleaseNotes |
NuGet package release notes e.g. https://... |
DotNetCoreMSBuildSettings
is used for all dotnet
commands e.g. dotnet pack project.csproj
MSBuildSettings
is used for calling MSBuild e.g. msbuild /t:build project.csproj
DotNetCoreMSBuildSettings
already has some of these extensions today: SetVersion
, SetVersionPrefix
, SetVersionSuffix
, SetFileVersion
, and SetInformationalVersion
, however MSBuildSettings
doesn't have any of them yet. I'll make sure these properties exist on both, and also add SetAssemblyVersion
, SetPackageVersion
, and SetPackageReleaseNotes
to bothDotNetCoreMSBuildSettings
or MSBuildSettings
. I'll add them to bothDotNetCoreBuild
:DotNetCoreBuild("./Project.csproj", new DotNetCoreBuildSettings
{
Configuration = configuration,
NoRestore = true,
NoIncremental = false,
MSBuildSettings = new DotNetCoreMSBuildSettings()
.SetVersion("1.2.3-pre")
.SetAssemblyVersion("1.0.0.0")
.SetFileVersion("1.2.3.0")
.InformationalVersion("1.2.3-pre+7ad03d0")
});
DotNetCorePack
:DotNetCorePack("Project.csproj", new DotNetCorePackSettings
{
Configuration = "Release",
NoRestore = true,
NoBuild = true,
OutputDirectory = "./artifact/nuget",
// ...
MSBuildSettings = new DotNetCoreMSBuildSettings()
.SetPackageVersion("1.2.3-pre")
.SetPackageReleaseNotes("https://github.com/cake-build/cake/releases")
});
:tada: This issue has been resolved in version v1.3.0 :tada:
The release is available on:
Your GitReleaseManager bot :package::rocket:
Discussed in https://github.com/cake-build/cake/discussions/3448
Relates to https://github.com/cake-build/cake/issues/3447 and could be done together in the same PR