-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Microsoft.NET.GenerateAssemblyInfo.targets
171 lines (149 loc) · 10.4 KB
/
Microsoft.NET.GenerateAssemblyInfo.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!--
***********************************************************************************************
Microsoft.NET.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>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<GeneratedAssemblyInfoFile Condition="'$(GeneratedAssemblyInfoFile)' ==''">$(IntermediateOutputPath)$(MSBuildProjectName).AssemblyInfo$(DefaultLanguageSourceExtension)</GeneratedAssemblyInfoFile>
<GenerateAssemblyInfo Condition="'$(GenerateAssemblyInfo)' == ''">true</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(GenerateAssemblyInfo)' == 'true'">
<GenerateAssemblyCompanyAttribute Condition="'$(GenerateAssemblyCompanyAttribute)' == ''">true</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyConfigurationAttribute Condition="'$(GenerateAssemblyConfigurationAttribute)' == ''">true</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCopyrightAttribute Condition="'$(GenerateAssemblyCopyrightAttribute)' == ''">true</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyDescriptionAttribute Condition="'$(GenerateAssemblyDescriptionAttribute)' == ''">true</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyFileVersionAttribute Condition="'$(GenerateAssemblyFileVersionAttribute)' == ''">true</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute Condition="'$(GenerateAssemblyInformationalVersionAttribute)' == ''">true</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyProductAttribute Condition="'$(GenerateAssemblyProductAttribute)' == ''">true</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute Condition="'$(GenerateAssemblyTitleAttribute)' == ''">true</GenerateAssemblyTitleAttribute>
<GenerateAssemblyVersionAttribute Condition="'$(GenerateAssemblyVersionAttribute)' == ''">true</GenerateAssemblyVersionAttribute>
<GenerateNeutralResourcesLanguageAttribute Condition="'$(GenerateNeutralResourcesLanguageAttribute)' == ''">true</GenerateNeutralResourcesLanguageAttribute>
<IncludeSourceRevisionInInformationalVersion Condition="'$(IncludeSourceRevisionInInformationalVersion)' == ''">true</IncludeSourceRevisionInInformationalVersion>
</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;CoreGenerateAssemblyInfo"
Condition="'$(GenerateAssemblyInfo)' == 'true'" />
<Target Name="AddSourceRevisionToInformationalVersion"
DependsOnTargets="GetAssemblyVersion;InitializeSourceControlInformation"
Condition="'$(SourceControlInformationFeatureSupported)' == 'true' and '$(IncludeSourceRevisionInInformationalVersion)' == 'true'">
<PropertyGroup Condition="'$(SourceRevisionId)' != ''">
<!-- Follow SemVer 2.0 rules -->
<_InformationalVersionContainsPlus>false</_InformationalVersionContainsPlus>
<_InformationalVersionContainsPlus Condition="$(InformationalVersion.Contains('+'))">true</_InformationalVersionContainsPlus>
<InformationalVersion Condition="!$(_InformationalVersionContainsPlus)">$(InformationalVersion)+$(SourceRevisionId)</InformationalVersion>
<InformationalVersion Condition="$(_InformationalVersionContainsPlus)">$(InformationalVersion).$(SourceRevisionId)</InformationalVersion>
</PropertyGroup>
</Target>
<Target Name="GetAssemblyAttributes"
DependsOnTargets="GetAssemblyVersion;AddSourceRevisionToInformationalVersion">
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyCompanyAttribute" Condition="'$(Company)' != '' and '$(GenerateAssemblyCompanyAttribute)' == 'true'">
<_Parameter1>$(Company)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyConfigurationAttribute" Condition="'$(Configuration)' != '' and '$(GenerateAssemblyConfigurationAttribute)' == 'true'">
<_Parameter1>$(Configuration)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyCopyrightAttribute" Condition="'$(Copyright)' != '' and '$(GenerateAssemblyCopyrightAttribute)' == 'true'">
<_Parameter1>$(Copyright)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyDescriptionAttribute" Condition="'$(Description)' != '' and '$(GenerateAssemblyDescriptionAttribute)' == 'true'">
<_Parameter1>$(Description)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyFileVersionAttribute" Condition="'$(FileVersion)' != '' and '$(GenerateAssemblyFileVersionAttribute)' == 'true'">
<_Parameter1>$(FileVersion)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyInformationalVersionAttribute" Condition="'$(InformationalVersion)' != '' and '$(GenerateAssemblyInformationalVersionAttribute)' == 'true'">
<_Parameter1>$(InformationalVersion)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyProductAttribute" Condition="'$(Product)' != '' and '$(GenerateAssemblyProductAttribute)' == 'true'">
<_Parameter1>$(Product)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyTitleAttribute" Condition="'$(AssemblyTitle)' != '' and '$(GenerateAssemblyTitleAttribute)' == 'true'">
<_Parameter1>$(AssemblyTitle)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyVersionAttribute" Condition="'$(AssemblyVersion)' != '' and '$(GenerateAssemblyVersionAttribute)' == 'true'">
<_Parameter1>$(AssemblyVersion)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Resources.NeutralResourcesLanguageAttribute" Condition="'$(NeutralLanguage)' != '' and '$(GenerateNeutralResourcesLanguageAttribute)' == 'true'">
<_Parameter1>$(NeutralLanguage)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Target>
<!--
To allow version changes to be respected on incremental builds (e.g. through CLI parameters),
create a hash of all assembly attributes so that the cache file will change with the calculated
assembly attribute values and msbuild will then execute CoreGenerateAssembly to generate a new file.
-->
<Target Name="CreateGeneratedAssemblyInfoInputsCacheFile"
DependsOnTargets="GetAssemblyAttributes">
<PropertyGroup>
<GeneratedAssemblyInfoInputsCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).AssemblyInfoInputs.cache</GeneratedAssemblyInfoInputsCacheFile>
</PropertyGroup>
<!-- We only use up to _Parameter1 for most attributes, but other targets may add additional assembly attributes with multiple parameters. -->
<Hash ItemsToHash="@(AssemblyAttribute->'%(Identity)%(_Parameter1)%(_Parameter2)%(_Parameter3)%(_Parameter4)%(_Parameter5)%(_Parameter6)%(_Parameter7)%(_Parameter8)')">
<Output TaskParameter="HashResult" PropertyName="_AssemblyAttributesHash" />
</Hash>
<WriteLinesToFile Lines="$(_AssemblyAttributesHash)" File="$(GeneratedAssemblyInfoInputsCacheFile)" Overwrite="True" WriteOnlyWhenDifferent="True" />
<ItemGroup>
<FileWrites Include="$(GeneratedAssemblyInfoInputsCacheFile)" />
</ItemGroup>
</Target>
<Target Name="CoreGenerateAssemblyInfo"
Condition="'$(Language)'=='VB' or '$(Language)'=='C#'"
DependsOnTargets="CreateGeneratedAssemblyInfoInputsCacheFile"
Inputs="$(GeneratedAssemblyInfoInputsCacheFile)"
Outputs="$(GeneratedAssemblyInfoFile)">
<ItemGroup>
<!-- Ensure the generated assemblyinfo file is not already part of the Compile sources, as a workaround for https://github.com/dotnet/sdk/issues/114 -->
<Compile Remove="$(GeneratedAssemblyInfoFile)" />
</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>
<InformationalVersion Condition="'$(InformationalVersion)' == ''">$(Version)</InformationalVersion>
</PropertyGroup>
</Target>
</Project>