-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from nguerrera/gen-assembly-info
Generate AssemblyInfo attributes during build
- Loading branch information
Showing
16 changed files
with
208 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Tasks/Microsoft.NETCore.Build.Tasks/GetAssemblyVersion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using Newtonsoft.Json; | ||
using NuGet.Versioning; | ||
using System.Diagnostics; | ||
|
||
namespace Microsoft.DotNet.Core.Build.Tasks | ||
{ | ||
/// <summary> | ||
/// Determines the assembly version to use for a given semantic version. | ||
/// </summary> | ||
public class GetAssemblyVersion : Task | ||
{ | ||
/// <summary> | ||
/// The nuget version from which to get an assembly version portion. | ||
/// </summary> | ||
[Required] | ||
public string NuGetVersion { get; set; } | ||
|
||
/// <summary> | ||
/// The assembly version (major.minor.patch.revision) portion of the nuget version. | ||
/// </summary> | ||
[Output] | ||
public string AssemblyVersion { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
// Using try/catch instead of TryParse so that we don't need to maintain our own error message here. | ||
try | ||
{ | ||
AssemblyVersion = NuGet.Versioning.NuGetVersion.Parse(NuGetVersion).Version.ToString(); | ||
return true; | ||
} | ||
catch (ArgumentException ex) | ||
{ | ||
Log.LogError(ex.Message); | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...t.NETCore.Build.Tasks/build/netstandard1.0/Microsoft.NETCore.GenerateAssemblyInfo.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.NETCore.GenerateAssemblyInfo.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"> | ||
<!-- | ||
============================================================ | ||
GenerateAssemblyInfo | ||
Generates assembly info source to intermediate directory | ||
============================================================ | ||
--> | ||
<PropertyGroup> | ||
<GeneratedAssemblyInfoFile Condition="'$(GeneratedAssemblyInfoFile)' ==''">$(IntermediateOutputPath)$(MSBuildProjectName).AssemblyInfo$(DefaultLanguageSourceExtension)</GeneratedAssemblyInfoFile> | ||
<GenerateAssemblyInfo Condition="'$(GenerateAssemblyInfo)' == ''">true</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
Note that this must run before every invocation of CoreCompile to ensure that all compiler | ||
runs see the generated assembly info. There is at least one scenario involving Xaml | ||
where CoreCompile is invoked without other potential hooks such as Compile or CoreBuild, | ||
etc., so we hook directly on to CoreCompile. Furthermore, we must run *after* | ||
PrepareForBuild to ensure that the intermediate directory has been created. | ||
--> | ||
<Target Name="GenerateAssemblyInfo" | ||
BeforeTargets="CoreCompile" | ||
DependsOnTargets="PrepareForBuild;GetAssemblyVersion;CoreGenerateAssemblyInfo" | ||
Condition="'$(GenerateAssemblyInfo)' == 'true'" | ||
Inputs="$(MSBuildAllProjects)" | ||
Outputs="$(GeneratedAssemblyInfoFile)" /> | ||
|
||
<Target Name="CoreGenerateAssemblyInfo" | ||
Condition="'$(Language)'=='VB' or '$(Language)'=='C#'"> | ||
<ItemGroup> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyCompanyAttribute" Condition="'$(Authors)' != ''"> | ||
<_Parameter1>$(Authors)</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyConfigurationAttribute" Condition="'$(Configuration)' != ''"> | ||
<_Parameter1>$(Configuration)</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyCopyrightAttribute" Condition="'$(Copyright)' != ''"> | ||
<_Parameter1>$(Copyright)</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyDescriptionAttribute" Condition="'$(Description)' != ''"> | ||
<_Parameter1>$(Description)</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyFileVersionAttribute" Condition="'$(FileVersion)' != ''"> | ||
<_Parameter1>$(FileVersion)</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyInformationalVersionAttribute" Condition="'$(Version)' != ''"> | ||
<_Parameter1>$(Version)</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyProductAttribute" Condition="'$(Product)' != ''"> | ||
<_Parameter1>$(Product)</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyTitleAttribute" Condition="'$(AssemblyTitle)' != ''"> | ||
<_Parameter1>$(AssemblyTitle)</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyVersionAttribute" Condition="'$(AssemblyVersion)' != ''"> | ||
<_Parameter1>$(AssemblyVersion)</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Resources.NeutralResourcesLanguage" Condition="'$(NeutralLanguage)' != ''"> | ||
<_Parameter1>$(NeutralLanguage)</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
|
||
<WriteCodeFragment AssemblyAttributes="@(AssemblyAttribute)" Language="$(Language)" OutputFile="$(GeneratedAssemblyInfoFile)"> | ||
<Output TaskParameter="OutputFile" ItemName="Compile" /> | ||
<Output TaskParameter="OutputFile" ItemName="FileWrites" /> | ||
</WriteCodeFragment> | ||
</Target> | ||
|
||
|
||
<!-- | ||
================================================================== | ||
GetAssemblyVersion | ||
Parses the nuget package version set in $(Version) and returns | ||
the implied $(AssemblyVersion) and $(FileVersion). | ||
e.g.: | ||
<Version>1.2.3-beta.4</Version> | ||
implies: | ||
<AssemblyVersion>1.2.3</AssemblyVersion> | ||
<FileVersion>1.2.3</FileVersion> | ||
Note that if $(AssemblyVersion) or $(FileVersion) are are already set, it | ||
is considered an override of the default inference from $(Version) and they | ||
are left unchanged by this target. | ||
================================================================== | ||
--> | ||
<Target Name="GetAssemblyVersion"> | ||
<GetAssemblyVersion Condition="'$(AssemblyVersion)' == ''" NuGetVersion="$(Version)"> | ||
<Output TaskParameter="AssemblyVersion" PropertyName="AssemblyVersion" /> | ||
</GetAssemblyVersion> | ||
|
||
<PropertyGroup> | ||
<FileVersion Condition="'$(FileVersion)' == ''">$(AssemblyVersion)</FileVersion> | ||
</PropertyGroup> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
src/Templates/ProjectTemplates/CSharp/.NETCore/Common/AssemblyInfo.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters