Enable auto-generate the Version from Custom build task

This commit is contained in:
Sam Xu 2019-10-03 16:35:05 -07:00
parent a20aabf999
commit fe608056a4
8 changed files with 63 additions and 104 deletions

View File

@ -7,15 +7,14 @@
<Project>
<PropertyGroup>
<!-- Make sure any change to this file invoke a rebuild -->
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<EnlistmentRoot>$(MSBuildThisFileDirectory.TrimEnd('\'))</EnlistmentRoot>
<!-- Setup the EnlistmentRoot -->
<EnlistmentRoot Condition="'$(EnlistmentRoot)' == ''">$(MSBuildThisFileDirectory.TrimEnd('\'))</EnlistmentRoot>
</PropertyGroup>
<Import Project="$(EnlistmentRoot)\tool\Build.props" />
<PropertyGroup>
<!--OData has some project files with the same name that are targeted for different framework platforms. Isolate their intermediate output folders-->
<IntermediateOutputPath Condition="$(TargetFrameworkFolderName) != ''">$(IntermediateOutputPath.TrimEnd('\'))\$(TargetFrameworkFolderName)</IntermediateOutputPath>
</PropertyGroup>
</Project>

View File

@ -12,20 +12,24 @@ using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
// [assembly: AssemblyCompany("Microsoft Corporation")]
// If you want to control this metadata globally but not with the VersionProductName property, hard-code the value below.
// If you want to control this metadata at the individual project level with AssemblyInfo.cs, comment-out the line below.
// 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>
// [assembly: AssemblyProduct("%VersionProductName%")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft® .NET/.NET Core OData Extensions")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyTrademark("Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the U.S. and/or other countries.")]
[assembly: AssemblyCulture("")]
/*
#if (DEBUG || _DEBUG)
[assembly: AssemblyConfiguration("Debug")]
#endif
*/
// disable CLSCompliant as the common extensions library decided not to support this
// see https://github.com/aspnet/AspNetCore/issues/2689#issuecomment-354693946

View File

@ -6,11 +6,22 @@
<Project>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<EnlistmentRoot>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))\</EnlistmentRoot>
<!-- Make sure any change to this file invoke a rebuild -->
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<!-- Setup the EnlistmentRoot, without the last '\' -->
<EnlistmentRoot Condition="'$(EnlistmentRoot)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))</EnlistmentRoot>
<!--Including pdb file to support SourceLink, if enable it, add IncludeSymbolsInPackage in your project and set its value as true-->
<AllowedOutputExtensionsInPackageBuildOutputFolder Condition="'$(IncludeSymbolsInPackage)' == 'true'">$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<ShouldGenerateAssemblyAttributeFile Condition="'$(ShouldGenerateAssemblyAttributeFile)' == ''">true</ShouldGenerateAssemblyAttributeFile>
<!-- Disable GenerateAssemblyInfo to use the auto-generated AssemblyInfo.cs -->
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<Import Project="..\Build.props" />
<Import Project="$(EnlistToolPath)\versioning.props" />
</Project>

View File

@ -4,11 +4,7 @@
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<RootNamespace>Microsoft.OpenApi.OData</RootNamespace>
<TargetFrameworks>net461; netstandard2.0</TargetFrameworks>
<!-- <Company>Microsoft</Company> -->
<Product>Microsoft OData Extensions for Open API</Product>
<PackageId>Microsoft.OpenApi.OData.Reader</PackageId>
<Version>1.0.0</Version>
<Authors>Microsoft.OpenApi.OData.Reader</Authors>
<LangVersion Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">latest</LangVersion>
<LangVersion Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">latest</LangVersion>
<SignAssembly>true</SignAssembly>

View File

@ -12,9 +12,7 @@
<PropertyGroup>
<BuildDependsOn>
GenerateTextStringResources;
GenerateAssemblyAttributeFile;
GenerateVersionConstantsFile;
ExcludeAssemblyFilesFromSourceAnalysis;
$(BuildDependsOn);
</BuildDependsOn>
@ -22,32 +20,6 @@
<Target Name="AfterBuild" DependsOnTargets="$(AfterBuildDependsOn)"/>
<!-- ********************************************************************************************* -->
<!-- *** Generate resources from .txt format resource files -->
<!-- ********************************************************************************************* -->
<PropertyGroup>
<GenerateTextStringResourcesDependsOn>
PrepareForBuild;
GenerateStringResources;
</GenerateTextStringResourcesDependsOn>
</PropertyGroup>
<Target Name="GenerateTextStringResources"
Condition="'@(TextStringResource)' != ''"
DependsOnTargets="$(GenerateTextStringResourcesDependsOn)"/>
<Target Name="GenerateStringResources">
<ItemGroup>
<EmbeddedResource Include="@(TextStringResource)" Condition="'%(TextStringResource.GenerateResource)' == 'true'">
<!-- "Resx" indicates it should go through GenerateResource -->
<Type>Resx</Type>
<WithCulture>false</WithCulture>
<ManifestResourceName>%(Filename)</ManifestResourceName>
</EmbeddedResource>
</ItemGroup>
</Target>
<!-- ********************************************************************************************* -->
@ -57,8 +29,8 @@
<!-- ********************************************************************************************* -->
<Target Name="ExcludeAssemblyFilesFromSourceAnalysis">
<ItemGroup>
<Compile Condition="'%(Filename)%(Extension)'=='AssemblyAttributes.cs'
or '%(Filename)%(Extension)'=='AssemblyRefs.cs'
<Compile Condition="'%(Filename)%(Extension)'=='OpenApiODataAssemblyAttributes.cs'
or '%(Filename)%(Extension)'=='AssemblyRefs.cs'
or '%(Filename)%(Extension)'=='.NETFramework,Version=v4.0.AssemblyAttributes.cs'
or '%(Filename)%(Extension)'=='PlatformHelper.cs'
or '%(Filename)%(Extension)'=='VersionConstants.cs'
@ -73,8 +45,8 @@
<!-- *** Generate a file with assembly attributes and hook it into the build -->
<!-- ********************************************************************************************* -->
<Target Name="GenerateAssemblyAttributeFile"
Inputs="$(MSBuildProjectFile);$(CustomBuildExtensionsPath)\Versioning.props"
Outputs="$(IntermediateOutputPath.TrimEnd('\'))\AssemblyAttributes$(DefaultLanguageSourceExtension)"
Inputs="$(MSBuildProjectFile);$(EnlistToolPath)\versioning.props"
Outputs="$(IntermediateOutputPath.TrimEnd('\'))\OpenApiODataAssemblyAttributes$(DefaultLanguageSourceExtension)"
Condition="'$(ShouldGenerateAssemblyAttributeFile)' == 'true'">
<PropertyGroup>
@ -92,6 +64,7 @@ using System.Resources;
[assembly: AssemblyVersion("%VersionFullSemantic%")]
[assembly: SatelliteContractVersion("%VersionFull%")]
[assembly: AssemblyMetadata("Serviceable", "True")]
</GenerateAssemblyAttributeTemplateCSharp>
</PropertyGroup>
@ -100,7 +73,7 @@ using System.Resources;
</PropertyGroup>
<PropertyGroup>
<AssemblyAttributeOutputFile>$(IntermediateOutputPath.TrimEnd("\\"))\AssemblyAttributes$(DefaultLanguageSourceExtension)</AssemblyAttributeOutputFile>
<AssemblyAttributeOutputFile>$(IntermediateOutputPath.TrimEnd("\\"))\OpenApiODataAssemblyAttributes$(DefaultLanguageSourceExtension)</AssemblyAttributeOutputFile>
<AssemblyNameFull>$(AssemblyName)$(TargetExt)</AssemblyNameFull>
<AssemblyAttributeFileContentsTransformed>$([System.String]::Copy('$(GenerateAssemblyAttributeTemplate)').Replace("%25AssemblyNameFull%25",$(AssemblyNameFull)).Replace("%25VersionFull%25",$(VersionFull)).Replace("%25VersionFullSemantic%25",$(VersionFullSemantic)))</AssemblyAttributeFileContentsTransformed>
</PropertyGroup>
@ -124,54 +97,6 @@ using System.Resources;
<!-- ********************************************************************************************* -->
<!-- ********************************************************************************************* -->
<!-- *** Generate a file with version constants and hook it into the build -->
<!-- ********************************************************************************************* -->
<Target Name="GenerateVersionConstantsFile"
Inputs="$(MSBuildProjectFile);$(EnlistToolPath)\Versioning.props"
Outputs="$(IntermediateOutputPath.TrimEnd('\'))\VersionConstants$(DefaultLanguageSourceExtension)"
Condition="'$(ShouldGenerateVersionConstantsFile)' == 'true'">
<PropertyGroup>
<!--Add more templates if we generate VersionConstants files for other project types.-->
<GenerateVersionConstantsTemplate>UNDEFINED_GenerateVersionConstantsTemplate</GenerateVersionConstantsTemplate>
<GenerateVersionConstantsTemplateCSharp>
internal static class VersionConstants
{
internal const string ReleaseVersion = "%VersionFullSemantic%";
internal const string AssemblyVersion = "%VersionFullSemantic%";
}
</GenerateVersionConstantsTemplateCSharp>
</PropertyGroup>
<PropertyGroup>
<GenerateVersionConstantsTemplate>$(GenerateVersionConstantsTemplateCSharp)</GenerateVersionConstantsTemplate>
</PropertyGroup>
<PropertyGroup>
<VersionConstantsOutputFile>$(IntermediateOutputPath.TrimEnd("\\"))\VersionConstants$(DefaultLanguageSourceExtension)</VersionConstantsOutputFile>
<VersionConstantsFileContentsTransformed>$([System.String]::Copy('$(GenerateVersionConstantsTemplate)').Replace("%25VersionFull%25",$(VersionFull)).Replace("%25VersionFullSemantic%25",$(VersionFullSemantic)))</VersionConstantsFileContentsTransformed>
</PropertyGroup>
<Message Text="GenerateVersionConstantsFile: Generating $(VersionConstantsOutputFile)" Importance="high" Condition="'$(DebugMessages)' == 'true'"/>
<MakeDir Directories="$(IntermediateOutputPath)" Condition="!Exists($(IntermediateOutputPath))"/>
<WriteLinesToFile
File="$(VersionConstantsOutputFile)"
Lines="$(VersionConstantsFileContentsTransformed)"
Overwrite="true"
Encoding="Unicode"
ContinueOnError="false"/>
<ItemGroup>
<Compile Include="$(VersionConstantsOutputFile)" />
</ItemGroup>
</Target>
<!-- ********************************************************************************************* -->
<!-- Execute StyleCop for each project -->
<Import Project="$(StyleCopTargets)" Condition="Exists('$(StyleCopTargets)') and '$(RunStyleCop)' == 'true' and '$(EnableStyleCop)' == 'true'"/>

View File

@ -8,9 +8,13 @@
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<VersionRunBeforeTargets>$(VersionRunBeforeTargets);CoreCompile</VersionRunBeforeTargets>
<VersionOutputPath>$(EnlistmentRoot)\src\AssemblyInfo</VersionOutputPath>
<AssemblyInfoCommonFile Condition="'$(AssemblyInfoCommonFile)'==''">AssemblyInfoCommon$(DefaultLanguageSourceExtension)</AssemblyInfoCommonFile>
</PropertyGroup>
<ItemGroup>

View File

@ -7,15 +7,23 @@
<Project>
<PropertyGroup Label="Define Basic Properties">
<!-- Make sure any change to this file invoke a rebuild -->
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<EnlistmentRoot Condition=" '$(EnlistmentRoot)'=='' ">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))</EnlistmentRoot>
<EnlistmentRoot>$(EnlistmentRoot.TrimEnd({'\\'}))</EnlistmentRoot>
<EnlistToolPath Condition=" '$(EnlistToolPath)'=='' ">$(EnlistmentRoot)\tool</EnlistToolPath>
<!-- Setup the EnlistmentRoot, without the last '\' -->
<EnlistmentRoot Condition="'$(EnlistmentRoot)'==''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))</EnlistmentRoot>
<EnlistToolPath Condition=" '$(EnlistToolPath)'=='' ">$(EnlistmentRoot)\tool</EnlistToolPath>
</PropertyGroup>
<Import Project=".\versioning.props" />
<PropertyGroup>
<!-- Before/After injection Settings -->
<CustomBeforeMicrosoftCommonTargets>$(MSBuildThisFileDirectory)Before.Common.targets</CustomBeforeMicrosoftCommonTargets>
<CustomAfterMicrosoftCommonTargets>$(MSBuildThisFileDirectory)After.Common.targets</CustomAfterMicrosoftCommonTargets>
</PropertyGroup>

View File

@ -1,7 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
<!-- Set the version number: major, minor, build and release (i.e. alpha, beta or blank for RTM)-->
This file defines the version information.
-->
<Project>
<!-- Set the version number:
major,
minor,
build,
release (i.e. alpha, beta or blank for RTM)
-->
<PropertyGroup>
<VersionMajor Condition="'$(VersionMajor)' == ''">1</VersionMajor>
<VersionMinor Condition="'$(VersionMinor)' == ''">0</VersionMinor>
@ -20,8 +29,11 @@
overflows the Int16. The system convert below will throw errors when this happens.
-->
<PropertyGroup>
<VersionStartYear Condition="'$(VersionStartYear)' == ''">2017</VersionStartYear>
<VersionStartYear Condition="'$(VersionStartYear)' == ''">2019</VersionStartYear>
<!-- { Now.Year - 2019 + 1}{MM}{DD} -->
<VersionDateCode>$([System.Convert]::ToInt16('$([MSBuild]::Add(1, $([MSBuild]::Subtract($([System.DateTime]::Now.Year), $(VersionStartYear)))))$([System.DateTime]::Now.ToString("MMdd"))'))</VersionDateCode>
<VersionRevision Condition="'$(VersionRevision)' == '' OR '$(VersionRevision)' == '0'">$([System.Convert]::ToString($(VersionDateCode)))</VersionRevision>
</PropertyGroup>