Enable auto-generate the Version from Custom build task · microsoft/OpenAPI.NET.OData@fe60805 · GitHub
Skip to content

Commit fe60805

Browse files
committed
Enable auto-generate the Version from Custom build task
1 parent a20aabf commit fe60805

8 files changed

Lines changed: 63 additions & 104 deletions

File tree

Build.props

Lines changed: 5 additions & 6 deletions

src/AssemblyInfo/AssemblyInfoCommon.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@
1212
using System.Runtime.Versioning;
1313
using System.Security;
1414

15-
// [assembly: AssemblyCompany("Microsoft Corporation")]
1615
// If you want to control this metadata globally but not with the VersionProductName property, hard-code the value below.
1716
// If you want to control this metadata at the individual project level with AssemblyInfo.cs, comment-out the line below.
1817
// If you leave the line below unchanged, make sure to set the property in the root build.props, e.g.: <VersionProductName Condition="'$(VersionProductName)'==''">Your Product Name</VersionProductName>
1918
// [assembly: AssemblyProduct("%VersionProductName%")]
19+
20+
[assembly: AssemblyCompany("Microsoft Corporation")]
21+
22+
[assembly: AssemblyProduct("Microsoft® .NET/.NET Core OData Extensions")]
23+
2024
[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")]
25+
2126
[assembly: AssemblyTrademark("Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the U.S. and/or other countries.")]
27+
2228
[assembly: AssemblyCulture("")]
2329

24-
/*
2530
#if (DEBUG || _DEBUG)
2631
[assembly: AssemblyConfiguration("Debug")]
2732
#endif
28-
*/
2933

3034
// disable CLSCompliant as the common extensions library decided not to support this
3135
// see https://github.com/aspnet/AspNetCore/issues/2689#issuecomment-354693946

src/Build.props

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@
66
<Project>
77

88
<PropertyGroup>
9-
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
10-
<EnlistmentRoot>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))\</EnlistmentRoot>
9+
10+
<!-- Make sure any change to this file invoke a rebuild -->
11+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
12+
13+
<!-- Setup the EnlistmentRoot, without the last '\' -->
14+
<EnlistmentRoot Condition="'$(EnlistmentRoot)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))</EnlistmentRoot>
15+
16+
<!--Including pdb file to support SourceLink, if enable it, add IncludeSymbolsInPackage in your project and set its value as true-->
17+
<AllowedOutputExtensionsInPackageBuildOutputFolder Condition="'$(IncludeSymbolsInPackage)' == 'true'">$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
18+
19+
<ShouldGenerateAssemblyAttributeFile Condition="'$(ShouldGenerateAssemblyAttributeFile)' == ''">true</ShouldGenerateAssemblyAttributeFile>
20+
21+
<!-- Disable GenerateAssemblyInfo to use the auto-generated AssemblyInfo.cs -->
22+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1123
</PropertyGroup>
1224

1325
<Import Project="..\Build.props" />
14-
<Import Project="$(EnlistToolPath)\versioning.props" />
1526

1627
</Project>

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
55
<RootNamespace>Microsoft.OpenApi.OData</RootNamespace>
66
<TargetFrameworks>net461; netstandard2.0</TargetFrameworks>
7-
<!-- <Company>Microsoft</Company> -->
8-
<Product>Microsoft OData Extensions for Open API</Product>
97
<PackageId>Microsoft.OpenApi.OData.Reader</PackageId>
10-
<Version>1.0.0</Version>
11-
<Authors>Microsoft.OpenApi.OData.Reader</Authors>
128
<LangVersion Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">latest</LangVersion>
139
<LangVersion Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">latest</LangVersion>
1410
<SignAssembly>true</SignAssembly>

tool/After.Common.targets

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,14 @@
1212

1313
<PropertyGroup>
1414
<BuildDependsOn>
15-
GenerateTextStringResources;
1615
GenerateAssemblyAttributeFile;
17-
GenerateVersionConstantsFile;
1816
ExcludeAssemblyFilesFromSourceAnalysis;
1917
$(BuildDependsOn);
2018
</BuildDependsOn>
2119
</PropertyGroup>
2220

2321
<Target Name="AfterBuild" DependsOnTargets="$(AfterBuildDependsOn)"/>
2422

25-
<!-- ********************************************************************************************* -->
26-
<!-- *** Generate resources from .txt format resource files -->
27-
<!-- ********************************************************************************************* -->
28-
<PropertyGroup>
29-
<GenerateTextStringResourcesDependsOn>
30-
PrepareForBuild;
31-
GenerateStringResources;
32-
</GenerateTextStringResourcesDependsOn>
33-
</PropertyGroup>
34-
35-
<Target Name="GenerateTextStringResources"
36-
Condition="'@(TextStringResource)' != ''"
37-
DependsOnTargets="$(GenerateTextStringResourcesDependsOn)"/>
38-
39-
<Target Name="GenerateStringResources">
40-
41-
<ItemGroup>
42-
<EmbeddedResource Include="@(TextStringResource)" Condition="'%(TextStringResource.GenerateResource)' == 'true'">
43-
<!-- "Resx" indicates it should go through GenerateResource -->
44-
<Type>Resx</Type>
45-
<WithCulture>false</WithCulture>
46-
<ManifestResourceName>%(Filename)</ManifestResourceName>
47-
</EmbeddedResource>
48-
</ItemGroup>
49-
50-
</Target>
5123

5224
<!-- ********************************************************************************************* -->
5325

@@ -57,8 +29,8 @@
5729
<!-- ********************************************************************************************* -->
5830
<Target Name="ExcludeAssemblyFilesFromSourceAnalysis">
5931
<ItemGroup>
60-
<Compile Condition="'%(Filename)%(Extension)'=='AssemblyAttributes.cs'
61-
or '%(Filename)%(Extension)'=='AssemblyRefs.cs'
32+
<Compile Condition="'%(Filename)%(Extension)'=='OpenApiODataAssemblyAttributes.cs'
33+
or '%(Filename)%(Extension)'=='AssemblyRefs.cs'
6234
or '%(Filename)%(Extension)'=='.NETFramework,Version=v4.0.AssemblyAttributes.cs'
6335
or '%(Filename)%(Extension)'=='PlatformHelper.cs'
6436
or '%(Filename)%(Extension)'=='VersionConstants.cs'
@@ -73,8 +45,8 @@
7345
<!-- *** Generate a file with assembly attributes and hook it into the build -->
7446
<!-- ********************************************************************************************* -->
7547
<Target Name="GenerateAssemblyAttributeFile"
76-
Inputs="$(MSBuildProjectFile);$(CustomBuildExtensionsPath)\Versioning.props"
77-
Outputs="$(IntermediateOutputPath.TrimEnd('\'))\AssemblyAttributes$(DefaultLanguageSourceExtension)"
48+
Inputs="$(MSBuildProjectFile);$(EnlistToolPath)\versioning.props"
49+
Outputs="$(IntermediateOutputPath.TrimEnd('\'))\OpenApiODataAssemblyAttributes$(DefaultLanguageSourceExtension)"
7850
Condition="'$(ShouldGenerateAssemblyAttributeFile)' == 'true'">
7951

8052
<PropertyGroup>
@@ -92,6 +64,7 @@ using System.Resources;
9264
[assembly: AssemblyVersion("%VersionFullSemantic%")]
9365
[assembly: SatelliteContractVersion("%VersionFull%")]
9466
[assembly: AssemblyMetadata("Serviceable", "True")]
67+
9568
</GenerateAssemblyAttributeTemplateCSharp>
9669
</PropertyGroup>
9770

@@ -100,7 +73,7 @@ using System.Resources;
10073
</PropertyGroup>
10174

10275
<PropertyGroup>
103-
<AssemblyAttributeOutputFile>$(IntermediateOutputPath.TrimEnd("\\"))\AssemblyAttributes$(DefaultLanguageSourceExtension)</AssemblyAttributeOutputFile>
76+
<AssemblyAttributeOutputFile>$(IntermediateOutputPath.TrimEnd("\\"))\OpenApiODataAssemblyAttributes$(DefaultLanguageSourceExtension)</AssemblyAttributeOutputFile>
10477
<AssemblyNameFull>$(AssemblyName)$(TargetExt)</AssemblyNameFull>
10578
<AssemblyAttributeFileContentsTransformed>$([System.String]::Copy('$(GenerateAssemblyAttributeTemplate)').Replace("%25AssemblyNameFull%25",$(AssemblyNameFull)).Replace("%25VersionFull%25",$(VersionFull)).Replace("%25VersionFullSemantic%25",$(VersionFullSemantic)))</AssemblyAttributeFileContentsTransformed>
10679
</PropertyGroup>
@@ -124,54 +97,6 @@ using System.Resources;
12497

12598
<!-- ********************************************************************************************* -->
12699

127-
<!-- ********************************************************************************************* -->
128-
<!-- *** Generate a file with version constants and hook it into the build -->
129-
<!-- ********************************************************************************************* -->
130-
<Target Name="GenerateVersionConstantsFile"
131-
Inputs="$(MSBuildProjectFile);$(EnlistToolPath)\Versioning.props"
132-
Outputs="$(IntermediateOutputPath.TrimEnd('\'))\VersionConstants$(DefaultLanguageSourceExtension)"
133-
Condition="'$(ShouldGenerateVersionConstantsFile)' == 'true'">
134-
135-
<PropertyGroup>
136-
<!--Add more templates if we generate VersionConstants files for other project types.-->
137-
<GenerateVersionConstantsTemplate>UNDEFINED_GenerateVersionConstantsTemplate</GenerateVersionConstantsTemplate>
138-
<GenerateVersionConstantsTemplateCSharp>
139-
internal static class VersionConstants
140-
{
141-
internal const string ReleaseVersion = "%VersionFullSemantic%";
142-
internal const string AssemblyVersion = "%VersionFullSemantic%";
143-
}
144-
</GenerateVersionConstantsTemplateCSharp>
145-
</PropertyGroup>
146-
147-
<PropertyGroup>
148-
<GenerateVersionConstantsTemplate>$(GenerateVersionConstantsTemplateCSharp)</GenerateVersionConstantsTemplate>
149-
</PropertyGroup>
150-
151-
<PropertyGroup>
152-
<VersionConstantsOutputFile>$(IntermediateOutputPath.TrimEnd("\\"))\VersionConstants$(DefaultLanguageSourceExtension)</VersionConstantsOutputFile>
153-
<VersionConstantsFileContentsTransformed>$([System.String]::Copy('$(GenerateVersionConstantsTemplate)').Replace("%25VersionFull%25",$(VersionFull)).Replace("%25VersionFullSemantic%25",$(VersionFullSemantic)))</VersionConstantsFileContentsTransformed>
154-
</PropertyGroup>
155-
156-
<Message Text="GenerateVersionConstantsFile: Generating $(VersionConstantsOutputFile)" Importance="high" Condition="'$(DebugMessages)' == 'true'"/>
157-
158-
<MakeDir Directories="$(IntermediateOutputPath)" Condition="!Exists($(IntermediateOutputPath))"/>
159-
160-
<WriteLinesToFile
161-
File="$(VersionConstantsOutputFile)"
162-
Lines="$(VersionConstantsFileContentsTransformed)"
163-
Overwrite="true"
164-
Encoding="Unicode"
165-
ContinueOnError="false"/>
166-
167-
<ItemGroup>
168-
<Compile Include="$(VersionConstantsOutputFile)" />
169-
</ItemGroup>
170-
171-
</Target>
172-
173-
<!-- ********************************************************************************************* -->
174-
175100
<!-- Execute StyleCop for each project -->
176101
<Import Project="$(StyleCopTargets)" Condition="Exists('$(StyleCopTargets)') and '$(RunStyleCop)' == 'true' and '$(EnableStyleCop)' == 'true'"/>
177102

tool/Before.Common.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
<PropertyGroup>
1010
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
11+
1112
<VersionRunBeforeTargets>$(VersionRunBeforeTargets);CoreCompile</VersionRunBeforeTargets>
13+
1214
<VersionOutputPath>$(EnlistmentRoot)\src\AssemblyInfo</VersionOutputPath>
15+
1316
<AssemblyInfoCommonFile Condition="'$(AssemblyInfoCommonFile)'==''">AssemblyInfoCommon$(DefaultLanguageSourceExtension)</AssemblyInfoCommonFile>
17+
1418
</PropertyGroup>
1519

1620
<ItemGroup>

tool/Build.props

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@
77
<Project>
88

99
<PropertyGroup Label="Define Basic Properties">
10+
11+
<!-- Make sure any change to this file invoke a rebuild -->
1012
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
11-
<EnlistmentRoot Condition=" '$(EnlistmentRoot)'=='' ">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))</EnlistmentRoot>
12-
<EnlistmentRoot>$(EnlistmentRoot.TrimEnd({'\\'}))</EnlistmentRoot>
13-
<EnlistToolPath Condition=" '$(EnlistToolPath)'=='' ">$(EnlistmentRoot)\tool</EnlistToolPath>
13+
14+
<!-- Setup the EnlistmentRoot, without the last '\' -->
15+
<EnlistmentRoot Condition="'$(EnlistmentRoot)'==''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))</EnlistmentRoot>
16+
17+
<EnlistToolPath Condition=" '$(EnlistToolPath)'=='' ">$(EnlistmentRoot)\tool</EnlistToolPath>
18+
1419
</PropertyGroup>
1520

21+
<Import Project=".\versioning.props" />
22+
1623
<PropertyGroup>
1724
<!-- Before/After injection Settings -->
1825
<CustomBeforeMicrosoftCommonTargets>$(MSBuildThisFileDirectory)Before.Common.targets</CustomBeforeMicrosoftCommonTargets>
26+
1927
<CustomAfterMicrosoftCommonTargets>$(MSBuildThisFileDirectory)After.Common.targets</CustomAfterMicrosoftCommonTargets>
2028
</PropertyGroup>
2129

tool/versioning.props

Lines changed: 16 additions & 4 deletions

0 commit comments

Comments
 (0)