1 <Project InitialTargets="ValidateTargetOSLowercase">
4 For non-SDK projects that import this file and then import Microsoft.Common.targets,
5 tell Microsoft.Common.targets not to import Directory.Build.targets again
7 <ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>
10 <Import Project="$(RepositoryEngineeringDir)Analyzers.targets" />
11 <Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
12 <Import Project="$(RepositoryEngineeringDir)liveBuilds.targets" />
13 <Import Project="$(RepositoryEngineeringDir)generators.targets" />
14 <Import Project="$(RepositoryEngineeringDir)python.targets" />
15 <Import Project="$(RepositoryEngineeringDir)generatorProjects.targets" Condition="'$(IsGeneratorProject)' == 'true'" />
16 <Import Project="$(RepositoryEngineeringDir)resolveContract.targets" Condition="'$(IsSourceProject)' == 'true'" />
17 <Import Project="$(RepositoryEngineeringDir)packaging.targets" Condition="'$(IsPackable)' == 'true' and '$(MSBuildProjectExtension)' != '.pkgproj'" />
20 When .NET gets built from source, make the SDK aware there are bootstrap packages
21 for Microsoft.NETCore.App.Runtime.<rid> and Microsoft.NETCore.App.Crossgen2.<rid>.
23 <ItemGroup Condition="'$(DotNetBuildFromSource)' == 'true'">
24 <KnownFrameworkReference Update="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.NETCore.App')->WithMetadataValue('TargetFramework', '$(NetCoreAppCurrent)'))">
25 <RuntimePackRuntimeIdentifiers>$(PackageRID)</RuntimePackRuntimeIdentifiers>
26 </KnownFrameworkReference>
27 <KnownCrossgen2Pack Update="@(KnownCrossgen2Pack->WithMetadataValue('Identity', 'Microsoft.NETCore.App.Crossgen2')->WithMetadataValue('TargetFramework', '$(NetCoreAppCurrent)'))">
28 <Crossgen2RuntimeIdentifiers>$(PackageRID)</Crossgen2RuntimeIdentifiers>
30 <!-- Avoid references to Microsoft.AspNetCore.App.Runtime.<rid> -->
31 <KnownFrameworkReference Remove="Microsoft.AspNetCore.App" />
36 Define this here (not just in Versions.props) because the SDK resets it
37 unconditionally in Microsoft.NETCoreSdk.BundledVersions.props.
39 <NETCoreAppMaximumVersion>$(MajorVersion).$(MinorVersion)</NETCoreAppMaximumVersion>
40 <!-- SDK sets product to assembly but we want it to be our product name -->
41 <Product>Microsoft%AE .NET</Product>
42 <!-- Use the .NET product branding version for informational version description -->
43 <InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(VersionSuffix)' == ''">$(ProductVersion)</InformationalVersion>
44 <InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(PreReleaseVersionLabel)' == 'servicing'">$(ProductVersion)</InformationalVersion>
45 <InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(VersionSuffix)' != ''">$(ProductVersion)-$(VersionSuffix)</InformationalVersion>
49 <SupportedNETCoreAppTargetFramework Include=".NETCoreApp,Version=v$(NETCoreAppMaximumVersion)" DisplayName=".NET $(NETCoreAppMaximumVersion)" Alias="net$(NETCoreAppMaximumVersion)" />
52 <!-- The Default behavior in VS is to show files for the first target framework in TargetFrameworks property.
53 This is required to show all the files corresponding to all target frameworks in VS. -->
54 <ItemGroup Condition="'$(DefaultLanguageSourceExtension)' != '' and
55 ('$(BuildingInsideVisualStudio)' == 'true' or '$(DesignTimeBuild)' == 'true')">
56 <None Include="$(MSBuildProjectDirectory)\**\*$(DefaultLanguageSourceExtension)"
57 Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);@(Compile)" />
61 <ItemGroup Condition="'$(IsPackable)' == 'true'">
62 <!-- The sfxproj files add the license themselves. -->
63 <None Include="$(LicenseFile)"
64 PackagePath="$([System.IO.Path]::GetFileName('$(LicenseFile)'))"
66 Condition="'$(MSBuildProjectExtension)' != '.sfxproj' and '$(MSBuildProjectFile)' != 'msi.csproj'" />
67 <None Include="$(PackageThirdPartyNoticesFile)"
68 PackagePath="$([System.IO.Path]::GetFileName('$(PackageThirdPartyNoticesFile)'))"
73 <PackageDescription Condition="'$(PackageDescription)' == '' and '$(Description)' != ''">$(Description)</PackageDescription>
74 <RuntimePackageDisclaimer>Internal implementation package not meant for direct consumption. Please do not reference directly.</RuntimePackageDisclaimer>
75 <UseRuntimePackageDisclaimer Condition="'$(UseRuntimePackageDisclaimer)' == '' and
76 ($(MSBuildProjectName.StartsWith('runtime.native')) or '$(PackageTargetRuntime)' != '')">true</UseRuntimePackageDisclaimer>
77 <PackageDescription Condition="'$(PackageDescription)' != '' and '$(UseRuntimePackageDisclaimer)' == 'true'">$(RuntimePackageDisclaimer) %0A$(PackageDescription)</PackageDescription>
78 <PackageDescription Condition="'$(PackageDescription)' == '' and '$(UseRuntimePackageDisclaimer)' == 'true'">$(RuntimePackageDisclaimer)</PackageDescription>
79 <!-- Keep in sync as required by the Packaging SDK in Arcade. -->
80 <Description>$(PackageDescription)</Description>
83 <Target Name="ValidateTargetOSLowercase"
84 Condition="!$(TargetOS.Equals($(TargetOS.ToLower()), StringComparison.InvariantCulture))">
85 <Error Text="The passed-in TargetOS property value '$(TargetOS)' must be lowercase." />
89 <TargetPathWithTargetPlatformMoniker>
90 <IsReferenceAssemblyProject>$(IsReferenceAssemblyProject)</IsReferenceAssemblyProject>
91 </TargetPathWithTargetPlatformMoniker>
92 </ItemDefinitionGroup>
94 <Target Name="ValidateReferenceAssemblyProjectReferencesAndTargetFramework"
95 AfterTargets="ResolveReferences"
96 Condition="'$(IsReferenceAssemblyProject)' == 'true' and
97 '$(SkipValidateReferenceAssemblyProjectReferences)' != 'true'">
98 <Error Text="Reference assemblies must only reference other reference assemblies and '%(ReferencePath.ProjectReferenceOriginalItemSpec)' is not a reference assembly project and does not set 'ProduceReferenceAssembly'."
99 Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IsReferenceAssemblyProject)' != 'true' and '%(ReferencePath.ReferenceAssembly)' == ''" />
100 <Error Text="Reference assemblies must be TargetPlatform agnostic. $(MSBuildProjectName) incorrectly targets $(TargetFramework), platform: $(TargetPlatformIdentifier)."
101 Condition="'$(TargetPlatformIdentifier)' != ''" />
104 <!-- For experimental ref assemblies (which typically have the same name as a regular ref
105 assembly), bump their minor file version by 100 to make it distinguishable from the regular
107 <Target Name="UpdateExperimentalRefAssemblyFileVersion"
108 AfterTargets="_InitializeAssemblyVersion"
109 Condition="'$(IsReferenceAssemblyProject)' == 'true' and '$(IsExperimentalRefAssembly)' == 'true'">
111 <_FileVersionMaj>$(FileVersion.Split('.')[0])</_FileVersionMaj>
112 <_FileVersionMin>$(FileVersion.Split('.')[1])</_FileVersionMin>
113 <_FileVersionBld>$(FileVersion.Split('.')[2])</_FileVersionBld>
114 <_FileVersionRev>$(FileVersion.Split('.')[3])</_FileVersionRev>
115 <FileVersion>$(_FileVersionMaj).$([MSBuild]::Add($(_FileVersionMin), 100)).$(_FileVersionBld).$(_FileVersionRev)</FileVersion>
119 <!-- Allows building against source assemblies when the 'SkipUseReferenceAssembly' attribute is present on ProjectReference items. -->
120 <Target Name="HandleReferenceAssemblyAttributeForProjectReferences"
121 AfterTargets="ResolveProjectReferences"
122 BeforeTargets="FindReferenceAssembliesForReferences"
123 Condition="'@(ProjectReference)' != '' and '@(_ResolvedProjectReferencePaths)' != ''">
124 <!-- If we have a ProjectReference to CoreLib, we need to compile against implementation assemblies,
125 and ignore architecture mismatches in those implementation assemblies. -->
126 <PropertyGroup Condition="@(_ResolvedProjectReferencePaths->AnyHaveMetadataValue('MSBuildSourceProjectFile', '$(CoreLibProject)'))">
127 <CompileUsingReferenceAssemblies Condition="'$(CompileUsingReferenceAssemblies)' == ''">false</CompileUsingReferenceAssemblies>
128 <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
131 <!-- Clear the ReferenceAssembly attribute on resolved P2Ps that set SkipUseReferenceAssembly to true. -->
133 <_ResolvedProjectReferencePaths Condition="'%(_ResolvedProjectReferencePaths.SkipUseReferenceAssembly)' == 'true'"
134 ReferenceAssembly="" />
138 <!-- Filter out transitive P2Ps which should be excluded. -->
139 <Target Name="FilterTransitiveProjectReferences"
140 AfterTargets="IncludeTransitiveProjectReferences"
141 Condition="'$(DisableTransitiveProjectReferences)' != 'true' and
142 '@(DefaultReferenceExclusion)' != ''">
144 <_transitiveProjectReferenceWithProjectName Include="@(ProjectReference->Metadata('NuGetPackageId'))"
145 OriginalIdentity="%(Identity)" />
146 <_transitiveIncludedProjectReferenceWithProjectName Include="@(_transitiveProjectReferenceWithProjectName)"
147 Exclude="@(DefaultReferenceExclusion)" />
148 <_transitiveExcludedProjectReferenceWithProjectName Include="@(_transitiveProjectReferenceWithProjectName)"
149 Exclude="@(_transitiveIncludedProjectReferenceWithProjectName)" />
150 <ProjectReference Remove="@(_transitiveExcludedProjectReferenceWithProjectName->Metadata('OriginalIdentity'))" />
154 <!-- Filter out conflicting implicit assembly references. -->
155 <Target Name="FilterImplicitAssemblyReferences"
156 Condition="'$(DisableImplicitFrameworkReferences)' != 'true'"
157 DependsOnTargets="ResolveProjectReferences"
158 AfterTargets="ResolveTargetingPackAssets">
160 <_targetingPackReferenceExclusion Include="$(TargetName)" />
161 <_targetingPackReferenceExclusion Include="@(_ResolvedProjectReferencePaths->Metadata('Filename'))" />
162 <_targetingPackReferenceExclusion Include="@(DefaultReferenceExclusion)" />
165 <!-- Filter out shims from the targeting pack references as an opt-in. -->
166 <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
167 '$(SkipTargetingPackShimReferences)' == 'true'">
168 <_targetingPackReferenceExclusion Include="@(NetFxReference)" />
169 <_targetingPackReferenceExclusion Include="netstandard" />
173 <_targetingPackReferenceWithProjectName Include="@(Reference->WithMetadataValue('ExternallyResolved', 'true')->Metadata('Filename'))"
174 OriginalIdentity="%(Identity)" />
175 <_targetingPackIncludedReferenceWithProjectName Include="@(_targetingPackReferenceWithProjectName)"
176 Exclude="@(_targetingPackReferenceExclusion)" />
177 <_targetingPackExcludedReferenceWithProjectName Include="@(_targetingPackReferenceWithProjectName)"
178 Exclude="@(_targetingPackIncludedReferenceWithProjectName)" />
179 <Reference Remove="@(_targetingPackExcludedReferenceWithProjectName->Metadata('OriginalIdentity'))" />
183 <_targetingPackAnalyzerReferenceWithProjectName Include="@(Analyzer->WithMetadataValue('ExternallyResolved', 'true')->Metadata('Filename'))"
184 OriginalIdentity="%(Identity)" />
185 <_targetingPackIncludedAnalyzerReferenceWithProjectName Include="@(_targetingPackAnalyzerReferenceWithProjectName)"
186 Exclude="@(_targetingPackReferenceExclusion)" />
187 <_targetingPackExcludedAnalyzerReferenceWithProjectName Include="@(_targetingPackAnalyzerReferenceWithProjectName)"
188 Exclude="@(_targetingPackIncludedAnalyzerReferenceWithProjectName)" />
189 <Analyzer Remove="@(_targetingPackExcludedAnalyzerReferenceWithProjectName->Metadata('OriginalIdentity'))" />
194 Arcade SDK versioning is defined by static properties in a targets file: work around this by
195 moving properties based on versioning into a target.
197 <Target Name="GetProductVersions">
199 <IncludePreReleaseLabelInPackageVersion Condition="'$(DotNetFinalVersionKind)' != 'release'">true</IncludePreReleaseLabelInPackageVersion>
200 <IncludePreReleaseLabelInPackageVersion Condition="'$(SuppressFinalPackageVersion)' == 'true'">true</IncludePreReleaseLabelInPackageVersion>
201 <IncludePreReleaseLabelInPackageVersion Condition="'$(IsShipping)' != 'true'">true</IncludePreReleaseLabelInPackageVersion>
203 <IncludeBuildNumberInPackageVersion Condition="'$(StabilizePackageVersion)' != 'true'">true</IncludeBuildNumberInPackageVersion>
204 <IncludeBuildNumberInPackageVersion Condition="'$(SuppressFinalPackageVersion)' == 'true'">true</IncludeBuildNumberInPackageVersion>
205 <IncludeBuildNumberInPackageVersion Condition="'$(IsShipping)' != 'true'">true</IncludeBuildNumberInPackageVersion>
207 <ProductVersionSuffix Condition="'$(IncludePreReleaseLabelInPackageVersion)' == 'true'">-$(VersionSuffix)</ProductVersionSuffix>
208 <ProductBandVersion Condition="'$(ProductBandVersion)' == ''">$(MajorVersion).$(MinorVersion)</ProductBandVersion>
209 <ProductionVersion Condition="'$(ProductionVersion)' == ''">$(ProductBandVersion).$(PatchVersion)</ProductionVersion>
210 <ProductVersion>$(ProductionVersion)$(ProductVersionSuffix)</ProductVersion>
212 <SharedFrameworkNugetVersion>$(ProductVersion)</SharedFrameworkNugetVersion>
213 <NuGetVersion>$(SharedFrameworkNugetVersion)</NuGetVersion>
214 <InstallersRelativePath>Runtime/$(SharedFrameworkNugetVersion)/</InstallersRelativePath>
217 By default, we are always building the nuget packages for HostPolicy, HostFXR and
218 Dotnet/AppHost. Thus, the properties (below) are always set to $(ProductVersion).
219 However, there are scenarios when only some of these components will change (e.g. during
220 servicing, we may only change HostPolicy but not HostFXR and Dotnet/AppHost). In such cases,
221 pass the appropriate version value(s) as argument to the build command in order to override;
222 e.g. 'build -p:HostPolicyVersion=x.y.z ...'
224 <HostVersion Condition="'$(HostVersion)' == ''">$(ProductVersion)</HostVersion>
225 <AppHostVersion Condition="'$(AppHostVersion)' == ''">$(ProductVersion)</AppHostVersion>
226 <HostResolverVersion Condition="'$(HostResolverVersion)' == ''">$(ProductVersion)</HostResolverVersion>
227 <HostPolicyVersion Condition="'$(HostPolicyVersion)' == ''">$(ProductVersion)</HostPolicyVersion>