Skip to content

Commit

Permalink
Merge pull request #819 from nguerrera/version-issue
Browse files Browse the repository at this point in the history
Set version early enough not to be overridden by winfx targets on desktop
  • Loading branch information
srivatsn authored Feb 5, 2017
2 parents 0cb29b7 + 55ec886 commit b11de8d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<None Include="buildCrossTargeting\Microsoft.NET.Sdk.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="build\Microsoft.NET.DefaultAssemblyInfo.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="build\Microsoft.NET.DefaultOutputPaths.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
***********************************************************************************************
Microsoft.NET.DefaultAssemlyInfo.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<PropertyGroup Condition=" '$(Version)' == '' ">
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">1.0.0</VersionPrefix>
<Version Condition=" '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</Version>
<Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
</PropertyGroup>

<PropertyGroup>
<Authors Condition=" '$(Authors)'=='' ">$(AssemblyName)</Authors>
<Company Condition=" '$(Company)'=='' ">$(Authors)</Company>
<AssemblyTitle Condition=" '$(AssemblyTitle)' == '' ">$(AssemblyName)</AssemblyTitle>
<Product Condition=" '$(Product)' == ''">$(AssemblyName)</Product>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultAssemblyInfo.targets" />

<!-- Set default intermediate and output paths -->
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.DefaultOutputPaths.targets" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

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

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<MicrosoftNETBuildTasksAssembly>$(MicrosoftNETBuildTasksDirectory)Microsoft.NET.Build.Tasks.dll</MicrosoftNETBuildTasksAssembly>
</PropertyGroup>

<PropertyGroup>
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">1.0.0</VersionPrefix>
<VersionSuffix Condition=" '$(VersionSuffix)' == '' "></VersionSuffix>
<Version Condition=" '$(Version)' == '' and '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</Version>
<Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
<Authors Condition=" '$(Authors)'=='' ">$(AssemblyName)</Authors>
<Company Condition=" '$(Company)'=='' ">$(Authors)</Company>
<AssemblyTitle Condition="'$(AssemblyTitle)' == ''">$(AssemblyName)</AssemblyTitle>
<Product Condition="'$(Product)' == ''">$(AssemblyName)</Product>
</PropertyGroup>

<UsingTask TaskName="GetNearestTargetFramework" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
<UsingTask TaskName="NETSdkError" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Xunit;
using FluentAssertions;
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;
using System.Runtime.InteropServices;

namespace Microsoft.NET.Build.Tests
{
Expand Down Expand Up @@ -82,5 +83,34 @@ public void It_respects_opt_outs(string attributeToOptOut)

actualInfo.Should().Equal(expectedInfo);
}

[Theory]
[InlineData("netcoreapp1.0")]
[InlineData("net45")]
public void It_respects_version_prefix(string targetFramework)
{
if (targetFramework == "net45" && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return;
}

var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld", identifier: targetFramework)
.WithSource()
.Restore("", $"/p:OutputType=Library;TargetFramework={targetFramework}");

var buildCommand = new BuildCommand(Stage0MSBuild, testAsset.TestRoot);
buildCommand
.Execute($"/p:OutputType=Library;TargetFramework={targetFramework};VersionPrefix=1.2.3")
.Should()
.Pass();

var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory(targetFramework).FullName, "HelloWorld.dll");
var info = AssemblyInfo.Get(assemblyPath);

info["AssemblyVersionAttribute"].Should().Be("1.2.3.0");
info["AssemblyFileVersionAttribute"].Should().Be("1.2.3.0");
info["AssemblyInformationalVersionAttribute"].Should().Be("1.2.3");
}
}
}

0 comments on commit b11de8d

Please sign in to comment.