Is it possible to get nuspec version of the form 1.2.3.4+Commit when using msbuild pack target?
We have two ways to produce a nuget package:
- With an explicit nuspec file.
- Using msbuild nuspec properties.
I am exploring the second possibility. The demo project is on github - https://github.com/MarkKharitonov/MSBuildPackNuspecVersionDemo.git
Running build.ps1 prints these lines:
Building ...
Packing ...
Dll Product Version = 1.2.3.4+8d50ec0
Nuspec Version = 1.2.3.4
I wonder if it is possible to have Nuspec version include the commit just like the Dll Product version.
The important files are:
Directory.Build.props:
<Project>
<PropertyGroup>
<SourceControlInformationFeatureSupported>true</SourceControlInformationFeatureSupported>
<Version>1.2.3.4</Version>
<RepositoryType>git</RepositoryType>
<RepositoryBranch>master</RepositoryBranch>
</PropertyGroup>
<Target Name="InitializeSourceControlInformation" />
</Project>
and build.ps1:
$ErrorActionPreference = "Stop"
$LocateMSBuild = $true
if (Get-Command msbuild -ErrorAction SilentlyContinue)
{
$MSBuildVersion = [Version](msbuild /nologo /version)
$LocateMSBuild = $MSBuildVersion.Major -lt 15
if (!$LocateMSBuild)
{
$MSBuild = "msbuild"
}
}
if ($LocateMSBuild)
{
$MSBuildHome = @("Enterprise", "Professional", "BuildTools", "Community") |ForEach-Object {
"C:Program Files (x86)Microsoft Visual Studio2017$_MSBuild15.0"
} |Where-Object { Test-Path "$_binmsbuild.exe" } | Select-Object -First 1
if (!$MSBuildHome)
{
throw "Failed to locate msbuild 15"
}
$MSBuild = "$MSBuildHomebinmsbuild.exe"
}
$Properties = @{
SourceRevisionId = $(git rev-parse --short HEAD)
RepositoryUrl = $(git remote get-url origin)
}
$MSBuildProperties = $Properties.GetEnumerator() | Where-Object {
$_.Value
} | ForEach-Object {
"/p:{0}={1}" -f $_.Key,$_.Value
}
Write-Host "Building ..."
&$MSBuild /restore /v:q /nologo /nr:false $MSBuildProperties
if ($LastExitCode)
{
exit $LastExitCode
}
Write-Host "Packing ..."
Remove-Item srcbinDebug*nupkg -ErrorAction SilentlyContinue
&$MSBuild /v:q /nologo /nr:false $MSBuildProperties /t:pack
if ($LastExitCode)
{
exit $LastExitCode
}
$Dll = "srcbinDebugnetstandard2PackVersionTest.dll"
$VersionInfo = (Get-Item $Dll).VersionInfo
"Dll Product Version = $($VersionInfo.ProductVersion)"
$Nuspec = "srcobjDebugPackVersionTest.1.2.3.4.nuspec"
$Pattern = '.*<version>(.+)</version>'
$NuspecVersion = (Select-String -path $Nuspec -Pattern $Pattern) -replace $Pattern,'$1'
"Nuspec Version = $NuspecVersion"
msbuild nuget version pack nuspec
add a comment |
We have two ways to produce a nuget package:
- With an explicit nuspec file.
- Using msbuild nuspec properties.
I am exploring the second possibility. The demo project is on github - https://github.com/MarkKharitonov/MSBuildPackNuspecVersionDemo.git
Running build.ps1 prints these lines:
Building ...
Packing ...
Dll Product Version = 1.2.3.4+8d50ec0
Nuspec Version = 1.2.3.4
I wonder if it is possible to have Nuspec version include the commit just like the Dll Product version.
The important files are:
Directory.Build.props:
<Project>
<PropertyGroup>
<SourceControlInformationFeatureSupported>true</SourceControlInformationFeatureSupported>
<Version>1.2.3.4</Version>
<RepositoryType>git</RepositoryType>
<RepositoryBranch>master</RepositoryBranch>
</PropertyGroup>
<Target Name="InitializeSourceControlInformation" />
</Project>
and build.ps1:
$ErrorActionPreference = "Stop"
$LocateMSBuild = $true
if (Get-Command msbuild -ErrorAction SilentlyContinue)
{
$MSBuildVersion = [Version](msbuild /nologo /version)
$LocateMSBuild = $MSBuildVersion.Major -lt 15
if (!$LocateMSBuild)
{
$MSBuild = "msbuild"
}
}
if ($LocateMSBuild)
{
$MSBuildHome = @("Enterprise", "Professional", "BuildTools", "Community") |ForEach-Object {
"C:Program Files (x86)Microsoft Visual Studio2017$_MSBuild15.0"
} |Where-Object { Test-Path "$_binmsbuild.exe" } | Select-Object -First 1
if (!$MSBuildHome)
{
throw "Failed to locate msbuild 15"
}
$MSBuild = "$MSBuildHomebinmsbuild.exe"
}
$Properties = @{
SourceRevisionId = $(git rev-parse --short HEAD)
RepositoryUrl = $(git remote get-url origin)
}
$MSBuildProperties = $Properties.GetEnumerator() | Where-Object {
$_.Value
} | ForEach-Object {
"/p:{0}={1}" -f $_.Key,$_.Value
}
Write-Host "Building ..."
&$MSBuild /restore /v:q /nologo /nr:false $MSBuildProperties
if ($LastExitCode)
{
exit $LastExitCode
}
Write-Host "Packing ..."
Remove-Item srcbinDebug*nupkg -ErrorAction SilentlyContinue
&$MSBuild /v:q /nologo /nr:false $MSBuildProperties /t:pack
if ($LastExitCode)
{
exit $LastExitCode
}
$Dll = "srcbinDebugnetstandard2PackVersionTest.dll"
$VersionInfo = (Get-Item $Dll).VersionInfo
"Dll Product Version = $($VersionInfo.ProductVersion)"
$Nuspec = "srcobjDebugPackVersionTest.1.2.3.4.nuspec"
$Pattern = '.*<version>(.+)</version>'
$NuspecVersion = (Select-String -path $Nuspec -Pattern $Pattern) -replace $Pattern,'$1'
"Nuspec Version = $NuspecVersion"
msbuild nuget version pack nuspec
add a comment |
We have two ways to produce a nuget package:
- With an explicit nuspec file.
- Using msbuild nuspec properties.
I am exploring the second possibility. The demo project is on github - https://github.com/MarkKharitonov/MSBuildPackNuspecVersionDemo.git
Running build.ps1 prints these lines:
Building ...
Packing ...
Dll Product Version = 1.2.3.4+8d50ec0
Nuspec Version = 1.2.3.4
I wonder if it is possible to have Nuspec version include the commit just like the Dll Product version.
The important files are:
Directory.Build.props:
<Project>
<PropertyGroup>
<SourceControlInformationFeatureSupported>true</SourceControlInformationFeatureSupported>
<Version>1.2.3.4</Version>
<RepositoryType>git</RepositoryType>
<RepositoryBranch>master</RepositoryBranch>
</PropertyGroup>
<Target Name="InitializeSourceControlInformation" />
</Project>
and build.ps1:
$ErrorActionPreference = "Stop"
$LocateMSBuild = $true
if (Get-Command msbuild -ErrorAction SilentlyContinue)
{
$MSBuildVersion = [Version](msbuild /nologo /version)
$LocateMSBuild = $MSBuildVersion.Major -lt 15
if (!$LocateMSBuild)
{
$MSBuild = "msbuild"
}
}
if ($LocateMSBuild)
{
$MSBuildHome = @("Enterprise", "Professional", "BuildTools", "Community") |ForEach-Object {
"C:Program Files (x86)Microsoft Visual Studio2017$_MSBuild15.0"
} |Where-Object { Test-Path "$_binmsbuild.exe" } | Select-Object -First 1
if (!$MSBuildHome)
{
throw "Failed to locate msbuild 15"
}
$MSBuild = "$MSBuildHomebinmsbuild.exe"
}
$Properties = @{
SourceRevisionId = $(git rev-parse --short HEAD)
RepositoryUrl = $(git remote get-url origin)
}
$MSBuildProperties = $Properties.GetEnumerator() | Where-Object {
$_.Value
} | ForEach-Object {
"/p:{0}={1}" -f $_.Key,$_.Value
}
Write-Host "Building ..."
&$MSBuild /restore /v:q /nologo /nr:false $MSBuildProperties
if ($LastExitCode)
{
exit $LastExitCode
}
Write-Host "Packing ..."
Remove-Item srcbinDebug*nupkg -ErrorAction SilentlyContinue
&$MSBuild /v:q /nologo /nr:false $MSBuildProperties /t:pack
if ($LastExitCode)
{
exit $LastExitCode
}
$Dll = "srcbinDebugnetstandard2PackVersionTest.dll"
$VersionInfo = (Get-Item $Dll).VersionInfo
"Dll Product Version = $($VersionInfo.ProductVersion)"
$Nuspec = "srcobjDebugPackVersionTest.1.2.3.4.nuspec"
$Pattern = '.*<version>(.+)</version>'
$NuspecVersion = (Select-String -path $Nuspec -Pattern $Pattern) -replace $Pattern,'$1'
"Nuspec Version = $NuspecVersion"
msbuild nuget version pack nuspec
We have two ways to produce a nuget package:
- With an explicit nuspec file.
- Using msbuild nuspec properties.
I am exploring the second possibility. The demo project is on github - https://github.com/MarkKharitonov/MSBuildPackNuspecVersionDemo.git
Running build.ps1 prints these lines:
Building ...
Packing ...
Dll Product Version = 1.2.3.4+8d50ec0
Nuspec Version = 1.2.3.4
I wonder if it is possible to have Nuspec version include the commit just like the Dll Product version.
The important files are:
Directory.Build.props:
<Project>
<PropertyGroup>
<SourceControlInformationFeatureSupported>true</SourceControlInformationFeatureSupported>
<Version>1.2.3.4</Version>
<RepositoryType>git</RepositoryType>
<RepositoryBranch>master</RepositoryBranch>
</PropertyGroup>
<Target Name="InitializeSourceControlInformation" />
</Project>
and build.ps1:
$ErrorActionPreference = "Stop"
$LocateMSBuild = $true
if (Get-Command msbuild -ErrorAction SilentlyContinue)
{
$MSBuildVersion = [Version](msbuild /nologo /version)
$LocateMSBuild = $MSBuildVersion.Major -lt 15
if (!$LocateMSBuild)
{
$MSBuild = "msbuild"
}
}
if ($LocateMSBuild)
{
$MSBuildHome = @("Enterprise", "Professional", "BuildTools", "Community") |ForEach-Object {
"C:Program Files (x86)Microsoft Visual Studio2017$_MSBuild15.0"
} |Where-Object { Test-Path "$_binmsbuild.exe" } | Select-Object -First 1
if (!$MSBuildHome)
{
throw "Failed to locate msbuild 15"
}
$MSBuild = "$MSBuildHomebinmsbuild.exe"
}
$Properties = @{
SourceRevisionId = $(git rev-parse --short HEAD)
RepositoryUrl = $(git remote get-url origin)
}
$MSBuildProperties = $Properties.GetEnumerator() | Where-Object {
$_.Value
} | ForEach-Object {
"/p:{0}={1}" -f $_.Key,$_.Value
}
Write-Host "Building ..."
&$MSBuild /restore /v:q /nologo /nr:false $MSBuildProperties
if ($LastExitCode)
{
exit $LastExitCode
}
Write-Host "Packing ..."
Remove-Item srcbinDebug*nupkg -ErrorAction SilentlyContinue
&$MSBuild /v:q /nologo /nr:false $MSBuildProperties /t:pack
if ($LastExitCode)
{
exit $LastExitCode
}
$Dll = "srcbinDebugnetstandard2PackVersionTest.dll"
$VersionInfo = (Get-Item $Dll).VersionInfo
"Dll Product Version = $($VersionInfo.ProductVersion)"
$Nuspec = "srcobjDebugPackVersionTest.1.2.3.4.nuspec"
$Pattern = '.*<version>(.+)</version>'
$NuspecVersion = (Select-String -path $Nuspec -Pattern $Pattern) -replace $Pattern,'$1'
"Nuspec Version = $NuspecVersion"
msbuild nuget version pack nuspec
msbuild nuget version pack nuspec
edited Jan 1 at 20:45
mark
asked Jan 1 at 20:09
markmark
20k56189380
20k56189380
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I believe changing
<Version>1.2.3.4</Version>
to
<Version>1.2.3.4+$(SourceRevisionId)</Version>
should do it since the build script passes the git commit hash as a msbuild property named SourceRevisionId.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998585%2fis-it-possible-to-get-nuspec-version-of-the-form-1-2-3-4commit-when-using-msbui%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I believe changing
<Version>1.2.3.4</Version>
to
<Version>1.2.3.4+$(SourceRevisionId)</Version>
should do it since the build script passes the git commit hash as a msbuild property named SourceRevisionId.
add a comment |
I believe changing
<Version>1.2.3.4</Version>
to
<Version>1.2.3.4+$(SourceRevisionId)</Version>
should do it since the build script passes the git commit hash as a msbuild property named SourceRevisionId.
add a comment |
I believe changing
<Version>1.2.3.4</Version>
to
<Version>1.2.3.4+$(SourceRevisionId)</Version>
should do it since the build script passes the git commit hash as a msbuild property named SourceRevisionId.
I believe changing
<Version>1.2.3.4</Version>
to
<Version>1.2.3.4+$(SourceRevisionId)</Version>
should do it since the build script passes the git commit hash as a msbuild property named SourceRevisionId.
answered Jan 3 at 2:09
zivkanzivkan
1,494918
1,494918
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998585%2fis-it-possible-to-get-nuspec-version-of-the-form-1-2-3-4commit-when-using-msbui%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown