Skip to content

Commit b11de8d

Browse files
authored
Merge pull request #819 from nguerrera/version-issue
Set version early enough not to be overridden by winfx targets on desktop
2 parents 0cb29b7 + 55ec886 commit b11de8d

6 files changed

+67
-10
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
<None Include="buildCrossTargeting\Microsoft.NET.Sdk.targets">
9191
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9292
</None>
93+
<None Include="build\Microsoft.NET.DefaultAssemblyInfo.targets">
94+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
95+
</None>
9396
<None Include="build\Microsoft.NET.DefaultOutputPaths.targets">
9497
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9598
</None>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!--
2+
***********************************************************************************************
3+
Microsoft.NET.DefaultAssemlyInfo.targets
4+
5+
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6+
created a backup copy. Incorrect changes to this file will make it
7+
impossible to load or build your projects from the command-line or the IDE.
8+
9+
Copyright (c) .NET Foundation. All rights reserved.
10+
***********************************************************************************************
11+
-->
12+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
13+
14+
<PropertyGroup>
15+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
16+
</PropertyGroup>
17+
18+
<PropertyGroup Condition=" '$(Version)' == '' ">
19+
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">1.0.0</VersionPrefix>
20+
<Version Condition=" '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</Version>
21+
<Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
22+
</PropertyGroup>
23+
24+
<PropertyGroup>
25+
<Authors Condition=" '$(Authors)'=='' ">$(AssemblyName)</Authors>
26+
<Company Condition=" '$(Company)'=='' ">$(Authors)</Company>
27+
<AssemblyTitle Condition=" '$(AssemblyTitle)' == '' ">$(AssemblyName)</AssemblyTitle>
28+
<Product Condition=" '$(Product)' == ''">$(AssemblyName)</Product>
29+
</PropertyGroup>
30+
31+
</Project>

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Copyright (c) .NET Foundation. All rights reserved.
1515
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
1616
</PropertyGroup>
1717

18+
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultAssemblyInfo.targets" />
19+
1820
<!-- Set default intermediate and output paths -->
1921
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultOutputPaths.targets" />
2022

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Copyright (c) .NET Foundation. All rights reserved.
1111
-->
1212
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1313

14+
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultAssemblyInfo.targets" />
1415
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultOutputPaths.targets" />
1516

1617
</Project>

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.Common.targets

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ Copyright (c) .NET Foundation. All rights reserved.
2222
<MicrosoftNETBuildTasksAssembly>$(MicrosoftNETBuildTasksDirectory)Microsoft.NET.Build.Tasks.dll</MicrosoftNETBuildTasksAssembly>
2323
</PropertyGroup>
2424

25-
<PropertyGroup>
26-
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">1.0.0</VersionPrefix>
27-
<VersionSuffix Condition=" '$(VersionSuffix)' == '' "></VersionSuffix>
28-
<Version Condition=" '$(Version)' == '' and '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</Version>
29-
<Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
30-
<Authors Condition=" '$(Authors)'=='' ">$(AssemblyName)</Authors>
31-
<Company Condition=" '$(Company)'=='' ">$(Authors)</Company>
32-
<AssemblyTitle Condition="'$(AssemblyTitle)' == ''">$(AssemblyName)</AssemblyTitle>
33-
<Product Condition="'$(Product)' == ''">$(AssemblyName)</Product>
34-
</PropertyGroup>
3525

3626
<UsingTask TaskName="GetNearestTargetFramework" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
3727
<UsingTask TaskName="NETSdkError" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />

test/Microsoft.NET.Build.Tests/GivenThatWeWantToControlGeneratedAssemblyInfo.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Xunit;
1010
using FluentAssertions;
1111
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;
12+
using System.Runtime.InteropServices;
1213

1314
namespace Microsoft.NET.Build.Tests
1415
{
@@ -82,5 +83,34 @@ public void It_respects_opt_outs(string attributeToOptOut)
8283

8384
actualInfo.Should().Equal(expectedInfo);
8485
}
86+
87+
[Theory]
88+
[InlineData("netcoreapp1.0")]
89+
[InlineData("net45")]
90+
public void It_respects_version_prefix(string targetFramework)
91+
{
92+
if (targetFramework == "net45" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
93+
{
94+
return;
95+
}
96+
97+
var testAsset = _testAssetsManager
98+
.CopyTestAsset("HelloWorld", identifier: targetFramework)
99+
.WithSource()
100+
.Restore("", $"/p:OutputType=Library;TargetFramework={targetFramework}");
101+
102+
var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot);
103+
buildCommand
104+
.Execute($"/p:OutputType=Library;TargetFramework={targetFramework};VersionPrefix=1.2.3")
105+
.Should()
106+
.Pass();
107+
108+
var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory(targetFramework).FullName, "HelloWorld.dll");
109+
var info = AssemblyInfo.Get(assemblyPath);
110+
111+
info["AssemblyVersionAttribute"].Should().Be("1.2.3.0");
112+
info["AssemblyFileVersionAttribute"].Should().Be("1.2.3.0");
113+
info["AssemblyInformationalVersionAttribute"].Should().Be("1.2.3");
114+
}
85115
}
86116
}

0 commit comments

Comments
 (0)