Skip to content

Commit

Permalink
Replace custom targets for generating assembly attributes and source …
Browse files Browse the repository at this point in the history
…control info by using SDK features (dotnet#7504)
  • Loading branch information
natemcmaster authored Feb 13, 2019
1 parent 06d7fe7 commit 2ac4619
Show file tree
Hide file tree
Showing 31 changed files with 155 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .azure/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ jobs:
jobDisplayName: "Build: Linux Musl x64"
agentOs: Linux
buildScript: ./dockerbuild.sh alpine
buildArgs: --ci --pack --all -e KOREBUILD_SKIP_INSTALL_NETFX=0 --arch x64 --os-name linux-musl --no-build-nodejs --no-build-java -p:RepositoryBranch=$(Build.SourceBranchName)
buildArgs: --ci --pack --all -e KOREBUILD_SKIP_INSTALL_NETFX=0 --arch x64 --os-name linux-musl --no-build-nodejs --no-build-java
installNodeJs: false
afterBuild:
# Remove packages that are not rid-specific.
Expand Down
56 changes: 38 additions & 18 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@
<PackageLicenseUrl>https://raw.githubusercontent.com/aspnet/AspNetCore/2.0.0/LICENSE.txt</PackageLicenseUrl>
<!-- The SPDX name for the source license. See https://spdx.org/licenses/. -->
<PackageLicenseType>Apache-2.0</PackageLicenseType>
<!--
Suppress a warning about upcoming deprecation of PackageLicenseUrl. When embedding licenses are supported,
replace PackageLicenseUrl with PackageLicenseExpression.
-->
<NoWarn>$(NoWarn);NU5125</NoWarn>
<!-- Suppress warnings about using SemVer 2.0. -->
<NoWarn>$(NoWarn);NU5105</NoWarn>
<!-- Don't make missing XML docs a fatal build error, but still surface so we have visibility into undocumented APIs. -->
<WarningsNotAsErrors>$(WarningsNotAsErrors);CS1591</WarningsNotAsErrors>

<!-- Contact email address for NuGet packages and Linux installers. -->
<MaintainerEmail>nugetaspnet@microsoft.com</MaintainerEmail>
Expand All @@ -42,20 +33,46 @@
<SharedFxDescription>Shared Framework for hosting of Microsoft ASP.NET Core applications. It is open source, cross-platform and is supported by Microsoft. We hope you enjoy using it! If you do, please consider joining the active community of developers that are contributing to the project on GitHub ($(RepositoryUrl)). We happily accept issues and PRs.</SharedFxDescription>
</PropertyGroup>

<!-- Warnings and errors -->
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!--
Suppress NuGet warning about upcoming deprecation of PackageLicenseUrl. When embedding licenses are supported,
replace PackageLicenseUrl with PackageLicenseExpression.
-->
<NoWarn>$(NoWarn);NU5125</NoWarn>
<!-- Suppress NuGet warnings about using SemVer 2.0. -->
<NoWarn>$(NoWarn);NU5105</NoWarn>
<!-- Don't make missing XML docs a fatal build error, but still surface so we have visibility into undocumented APIs. -->
<WarningsNotAsErrors>$(WarningsNotAsErrors);CS1591</WarningsNotAsErrors>
<!-- xUnit1004 = warns about skipped tests. Make this a non-fatal build warning. -->
<WarningsNotAsErrors>$(WarningsNotAsErrors);xUnit1004</WarningsNotAsErrors>
</PropertyGroup>

<!-- Source code settings -->
<PropertyGroup>
<RepositoryRoot>$(MSBuildThisFileDirectory)</RepositoryRoot>
<RepositoryUrl>https://github.com/aspnet/AspNetCore</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<SharedSourceRoot>$(MSBuildThisFileDirectory)src\Shared\</SharedSourceRoot>
<GoogleTestSubmoduleRoot>$(RepositoryRoot)src\submodules\googletest\</GoogleTestSubmoduleRoot>
<!-- Embed source files that are not tracked by the source control manager in the PDB. -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- Additional assembly attributes are already configured to include the source revision ID. -->
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>

<!-- These project types are disabled because the presence of a PackageReference causes issues for NuGet. -->
<DisableSourceLink Condition="'$(MSBuildProjectExtension)' == '.zipproj' OR '$(MSBuildProjectExtension)' == '.debproj' OR '$(MSBuildProjectExtension)' == '.rpmproj'">true</DisableSourceLink>
</PropertyGroup>

<ItemGroup Condition="'$(DisableSourceLink)' != 'true'">
<!-- See https://github.com/dotnet/sourcelink -->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="$(MicrosoftSourceLinkGitHubPackageVersion)" PrivateAssets="All" AllowExplicitReference="true" />
<PackageReference Include="Microsoft.SourceLink.Vsts.Git" Version="$(MicrosoftSourceLinkVstsGitPackageVersion)" PrivateAssets="All" AllowExplicitReference="true" />
</ItemGroup>

<!-- Compilation options which apply to all languages. Language-specific options should be set in eng/targets/$(lang).Common.props -->
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)eng\AspNetCore.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<PlatformName Condition=" '$(PlatformName)' == '' ">$(Platform)</PlatformName>
Expand All @@ -77,16 +94,14 @@
linux-arm64
</SupportedRuntimeIdentifiers>

<!-- Instructs the compiler to use SHA256 instead of SHA1 when adding file hashes to PDBs. -->
<ChecksumAlgorithm>SHA256</ChecksumAlgorithm>
<!-- Make error messages clickable in VS Code's console -->
<GenerateFullPaths Condition="'$(VSCODE_PID)' != ''">true</GenerateFullPaths>

<!-- Suppress the message about using a preview version of .NET Core SDK. We are okay with this and don't need the warning. -->
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>

<!-- Fixes a common error in targets implementing a NoBuild mode. -->
<BuildProjectReferences Condition=" '$(NoBuild)' == 'true' ">false</BuildProjectReferences>

<!-- Enables Strict mode for Roslyn compiler -->
<Features>strict</Features>
</PropertyGroup>

<Import Project="eng\Versions.props" />
Expand Down Expand Up @@ -139,12 +154,17 @@
<IsTestAssetProject Condition="$(RepoRelativeProjectDir.Contains('testassets'))">true</IsTestAssetProject>
<IsSampleProject Condition="$(RepoRelativeProjectDir.Contains('sample'))">true</IsSampleProject>
<IsAnalyzersProject Condition="$(MSBuildProjectName.EndsWith('.Analyzers'))">true</IsAnalyzersProject>
<DisableDeterministicSourceRoot Condition="'$(IsSampleProject)' == 'true' OR '$(IsTestAssetProject)' == 'true'">true</DisableDeterministicSourceRoot>
</PropertyGroup>

<Import Project="build\tasks\RepoTasks.tasks" Condition="'$(MSBuildProjectName)' != 'RepoTasks' AND '$(DesignTimeBuild)' != 'true'" />

<PropertyGroup>
<ContinuousIntegrationBuild Condition="'$(CI)' == 'true'">true</ContinuousIntegrationBuild>
<!--
Disable deterministic source paths in test assets and samples.
In order for the debugger to find source files when debugging a locally built binary the PDB must contain original, unmapped local paths
-->
<DeterministicSourcePaths Condition="'$(IsSampleProject)' == 'true' OR '$(IsTestAssetProject)' == 'true'">false</DeterministicSourcePaths>
<!-- Projects which reference Microsoft.AspNetCore.Mvc.Testing should import this targets file to ensure dependency .deps.json files are copied into test output. -->
<MvcTestingTargets>$(MSBuildThisFileDirectory)src\Mvc\src\Microsoft.AspNetCore.Mvc.Testing\Microsoft.AspNetCore.Mvc.Testing.targets</MvcTestingTargets>
<!-- IIS native projects can only be built on Windows for x86 and x64. -->
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<BuildHelixPayload Condition="'$(BuildHelixPayload)' == '' AND '$(IsTestProject)' == 'true'">true</BuildHelixPayload>
</PropertyGroup>

<Import Project="eng\Workarounds.targets" />
<Import Project="eng\targets\ResolveIisReferences.targets" Condition=" '$(MSBuildProjectExtension)' != '.vcxproj' " />
<Import Project="eng\targets\Cpp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
<Import Project="eng\targets\CSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
Expand Down
8 changes: 4 additions & 4 deletions build/Maestro/Maestro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
</Target>

<Target Name="GenerateBuildAssetManifest"
DependsOnTargets="GetFilesToPublish;ResolveRepositoryBranch;ResolveCommitHash">
DependsOnTargets="GetFilesToPublish">

<GenerateBuildManifest
Artifacts="@(PackageToPublish)"
OutputPath="$(ManifestsPath)aspnetcore-$(TargetRuntimeIdentifier)-$(PackageVersion).xml"
BuildId="$(PackageVersion)"
RepoUri="$(RepositoryUrl)"
RepoBranch="$(RepositoryBranch)"
RepoCommit="$(RepositoryCommit)" />
RepoUri="$(BUILD_REPOSITORY_URI)"
RepoBranch="$(BUILD_SOURCEBRANCH)"
RepoCommit="$(BUILD_SOURCEVERSION)" />
</Target>

</Project>
2 changes: 1 addition & 1 deletion build/SharedFx.targets
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<Target Name="BuildSharedFx" DependsOnTargets="$(BuildSharedFxDependsOn)" />

<Target Name="_BuildSharedFxProjects" DependsOnTargets="ResolveCommitHash">
<Target Name="_BuildSharedFxProjects">

<PropertyGroup>
<_RestoreGraphProjectInput>@(FxProjectToBuild)</_RestoreGraphProjectInput>
Expand Down
1 change: 0 additions & 1 deletion build/repo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<Import Project="AzureIntegration.targets" />
<Import Project="SharedFx.targets" />
<Import Project="CodeSign.targets" />
<Import Project="..\eng\Workarounds.targets" />

<PropertyGroup>
<!-- Some projects need access to tasks bundled in KoreBuild. -->
Expand Down
5 changes: 4 additions & 1 deletion dockerbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fi
commit_hash="$(git rev-parse HEAD || true)"

if [ ! -z "$commit_hash" ]; then
build_args[${#build_args[*]}]="-p:RepositoryCommit=$commit_hash"
build_args[${#build_args[*]}]="-p:SourceRevisionId=$commit_hash"
fi

dockerfile="$DIR/build/docker/$image.Dockerfile"
Expand All @@ -118,6 +118,9 @@ docker run \
-e TEAMCITY_VERSION \
-e BUILD_NUMBER \
-e BUILD_BUILDNUMBER \
-e BUILD_REPOSITORY_URI \
-e BUILD_SOURCEVERSION \
-e BUILD_SOURCEBRANCH \
-e DOTNET_CLI_TELEMETRY_OPTOUT \
-e Configuration \
-v "$DIR:/code/build" \
Expand Down
2 changes: 2 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
<InternalAspNetCoreSdkPackageVersion Condition=" '$(KoreBuildVersion)' == '' ">3.0.0-build-20190130.1</InternalAspNetCoreSdkPackageVersion>
<MicrosoftNETFrameworkReferenceAssembliesPackageVersion>1.0.0-alpha-004</MicrosoftNETFrameworkReferenceAssembliesPackageVersion>
<MicrosoftNETTestSdkPackageVersion>15.9.0</MicrosoftNETTestSdkPackageVersion>
<MicrosoftSourceLinkGitHubPackageVersion>1.0.0-beta2-18618-05</MicrosoftSourceLinkGitHubPackageVersion>
<MicrosoftSourceLinkVstsGitPackageVersion>1.0.0-beta2-18618-05</MicrosoftSourceLinkVstsGitPackageVersion>
<!-- Stable dotnet/corefx packages no longer updated for .NET Core 3 -->
<SystemBuffersPackageVersion>4.5.0</SystemBuffersPackageVersion>
<SystemCodeDomPackageVersion>4.4.0</SystemCodeDomPackageVersion>
Expand Down
6 changes: 6 additions & 0 deletions eng/Workarounds.targets
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!-- Use this file to workaround issues. List the issue tracking the item to fix so we can remove the workaround when the issue is resolved. -->
<Project>

<!-- Workaround https://github.com/aspnet/AspNetCore/issues/7503. This chains GenerateSourceLinkFile before razor component targets run. -->
<Target Name="_EnsureSourceLinkHappensBeforeRazorComponentGeneration"
BeforeTargets="PrepareForRazorComponentGenerate"
DependsOnTargets="GenerateSourceLinkFile" />

</Project>
16 changes: 16 additions & 0 deletions eng/targets/CSharp.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

<PropertyGroup>
<LangVersion>7.3</LangVersion>

<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)..\AspNetCore.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>

<!-- Instructs the compiler to use SHA256 instead of SHA1 when adding file hashes to PDBs. -->
<ChecksumAlgorithm>SHA256</ChecksumAlgorithm>

<!-- Enables Strict mode for Roslyn compiler -->
<Features>strict</Features>

<!-- Disables targets in Internal.AspNetCore.Sdk which are obsolete. -->
<GenerateSourceLinkFile>false</GenerateSourceLinkFile>
<GenerateRepositoryCommitUrlInDescription>false</GenerateRepositoryCommitUrlInDescription>
<GenerateCommitHashAttribute>false</GenerateCommitHashAttribute>
<GenerateInternalAspNetCoreAttributes>false</GenerateInternalAspNetCoreAttributes>
<DisableDeterministicSourceRoot>true</DisableDeterministicSourceRoot>
</PropertyGroup>

<ItemGroup>
Expand Down
30 changes: 29 additions & 1 deletion eng/targets/CSharp.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,35 @@
<TargetFramework>net$(TargetFrameworkVersion.Substring(1).Replace('.',''))</TargetFramework>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
</PropertyGroup>


<Target Name="GetCustomAssemblyAttributes"
BeforeTargets="GetAssemblyAttributes"
DependsOnTargets="InitializeSourceControlInformation">

<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(SourceRevisionId)' != ''">
<_Parameter1>CommitHash</_Parameter1>
<_Parameter2>$(SourceRevisionId)</_Parameter2>
</AssemblyAttribute>

<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="$(RepositoryUrl.StartsWith('https://github.com'))">
<_Parameter1>SourceCommitUrl</_Parameter1>
<_Parameter2>$(RepositoryUrl)/tree/$(SourceRevisionId)</_Parameter2>
</AssemblyAttribute>

<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(Serviceable)' == 'true'">
<_Parameter1>Serviceable</_Parameter1>
<_Parameter2>True</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Target>

<Target Name="GetCustomFileVersion" BeforeTargets="GetAssemblyVersion">
<PropertyGroup Condition="'$(FileVerison)' == '' AND '$(FileRevisionVersion)' != ''">
<FileVersion>$(VersionPrefix).$(FileRevisionVersion)</FileVersion>
</PropertyGroup>
</Target>

<Import Project="Packaging.targets" />
<Import Project="ResolveReferences.targets" />
</Project>
13 changes: 13 additions & 0 deletions eng/targets/Packaging.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@
</ItemGroup>
</Target>

<PropertyGroup>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);_AppendRepostoryUrlToPackageDescription</GenerateNuspecDependsOn>
</PropertyGroup>

<Target Name="_AppendRepostoryUrlToPackageDescription"
DependsOnTargets="InitializeSourceControlInformation">
<PropertyGroup Condition="'$(RepositoryUrl)' != '' AND '$(SourceRevisionId)' != ''">
<PackageDescription>$(PackageDescription)

This package was built from the source code at $(RepositoryUrl)/tree/$(SourceRevisionId)</PackageDescription>
</PropertyGroup>
</Target>

</Project>
4 changes: 2 additions & 2 deletions eng/targets/Wix.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<PropertyGroup>
<!-- Required to make NuGet happy -->
<TargetFramework>net461</TargetFramework>
<TargetFrameworkMoniker>Native,Version=v0.0</TargetFrameworkMoniker>

<MSBuildProjectExtensionsPath>$(BaseIntermediateOutputPath)</MSBuildProjectExtensionsPath>
<MSBuildProjectExtensionsPath Condition="'$(MSBuildProjectExtensionsPath)' == ''">$(MSBuildProjectDir)\obj\</MSBuildProjectExtensionsPath>
<!-- IsRunningFromVisualStudio may be true even when running msbuild.exe from command line. This generally means that MSBUild is Visual Studio installation and therefore we need to find NuGet.targets in a different location. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,4 @@
<Reference Include="Microsoft.NET.Sdk.Razor" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(BuildNumber)' != ''">
<_Parameter1>BuildNumber</_Parameter1>
<_Parameter2>$(BuildNumber)</_Parameter2>
</RazorAssemblyAttribute>

<RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(BuildNumber)' != ''">
<_Parameter1>BuildNumber</_Parameter1>
<_Parameter2>$(BuildNumber)</_Parameter2>
</RazorTargetAssemblyAttribute>
</ItemGroup>

<ItemGroup>
<RazorCompile Include="$(GeneratedCommitHashAttributeFile)" />
<RazorCompile Include="$(GeneratedInternalAspNetCoreAttributeFile)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,4 @@
<Reference Include="Microsoft.NET.Sdk.Razor" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(BuildNumber)' != ''">
<_Parameter1>BuildNumber</_Parameter1>
<_Parameter2>$(BuildNumber)</_Parameter2>
</RazorAssemblyAttribute>

<RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(BuildNumber)' != ''">
<_Parameter1>BuildNumber</_Parameter1>
<_Parameter2>$(BuildNumber)</_Parameter2>
</RazorTargetAssemblyAttribute>
</ItemGroup>

<ItemGroup>
<RazorCompile Include="$(GeneratedCommitHashAttributeFile)" />
<RazorCompile Include="$(GeneratedInternalAspNetCoreAttributeFile)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
componentsversion=$(ComponentsPackageVersion);
razorversion=$(MicrosoftAspNetCoreRazorDesignPackageVersion);
blazormonoversion=$(MicrosoftAspNetCoreBlazorMonoPackageVersion);
repositorycommit=$(RepositoryCommit);</NuspecProperties>
repositorycommit=$(SourceRevisionId);</NuspecProperties>
</PropertyGroup>
<ItemGroup>
<_TargetFramework Include="$(TargetFramework)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
blazorversion=$(PackageVersion);
aspnetcoreversion=$(ComponentsPackageVersion);
sharedfxversion=$(SharedFxVersion);
repositorycommit=$(RepositoryCommit);</NuspecProperties>
repositorycommit=$(SourceRevisionId);</NuspecProperties>
</PropertyGroup>
<!-- Also temporarily generate the runtimeconfig.json manually until we can use <FrameworkReference> -->
<Sdk_GenerateFileFromTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
IncludeCustomRestoreSources=$(IncludeCustomRestoreSourcesValue);
TemplateBlazorVersion=$(PackageVersion);
TemplateComponentsVersion=$(ComponentsPackageVersion);
RepositoryCommit=$(RepositoryCommit);
RepositoryCommit=$(SourceRevisionId);
</GeneratedContentProperties>
</PropertyGroup>
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PropertyGroup>
<NuspecProperties>
version=$(PackageVersion);
repositorycommit=$(RepositoryCommit);
repositorycommit=$(SourceRevisionId);
</NuspecProperties>
</PropertyGroup>
</Target>
Expand Down
6 changes: 3 additions & 3 deletions src/Framework/src/SharedFx.targets
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ This targets file should only be imported by .shfxproj files.
</Target>

<!-- Generates the .version file in the shared framework -->
<Target Name="GenerateSharedFxVersionsFile">
<Target Name="GenerateSharedFxVersionsFile" DependsOnTargets="InitializeSourceControlInformation">
<ItemGroup>
<VersionLines Include="$(RepositoryCommit)" />
<VersionLines Include="$(SourceRevisionId)" />
<VersionLines Include="$(PackageVersion)" />
</ItemGroup>

Expand Down Expand Up @@ -369,7 +369,7 @@ This targets file should only be imported by .shfxproj files.
projectUrl=$(PackageProjectUrl);
iconUrl=$(PackageIconUrl);
repositoryUrl=$(RepositoryUrl);
repositoryCommit=$(RepositoryCommit);
repositoryCommit=$(SourceRevisionId);
copyright=$(Copyright);
targetFramework=$(TargetFramework);
symbolsAssets=$([MSBuild]::NormalizeDirectory($(SymbolsOutputPath)));
Expand Down
Loading

0 comments on commit 2ac4619

Please sign in to comment.