build/common.targets (169 lines of code) (raw):

<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0"> <!-- Set AssemblyVersion in targets as it is TFM dependent. --> <PropertyGroup Condition="'$(AssemblyVersion)' == ''"> <AssemblyVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">$(SemanticVersion).$(PreReleaseVersion)</AssemblyVersion> <AssemblyVersion Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">$(SemanticVersion).0</AssemblyVersion> </PropertyGroup> <!-- Compiler flags --> <PropertyGroup> <DefineConstants Condition="'$(TargetFramework)' == '$(NETFXTargetFramework)'">$(DefineConstants);IS_DESKTOP</DefineConstants> <DefineConstants Condition="'$(TargetFramework)' != '$(NETFXTargetFramework)'">$(DefineConstants);IS_CORECLR</DefineConstants> </PropertyGroup> <!-- Include shared files for test netcore projects --> <ItemGroup Condition="'$(SkipShared)' != 'true' AND '$(TestProject)' == 'true' "> <Compile Include="$(BuildCommonDirectory)TestShared\*.cs" /> </ItemGroup> <Target Name="_NuGetClientAddVsThreadingAnalyzerAdditionalFiles" AfterTargets="ResolvePackageAssets;ResolveNuGetPackageAssets"> <ItemGroup Condition=" '@(PackageDependencies->AnyHaveMetadataValue('Identity', 'Microsoft.VisualStudio.Threading.Analyzers'))' == 'true' OR '@(ReferencedNuGetPackages->AnyHaveMetadataValue('Identity', 'Microsoft.VisualStudio.Sdk'))' == 'true' "> <AdditionalFiles Include="$(SharedDirectory)\vs-threading.*.txt" /> </ItemGroup> </Target> <Import Project="sign.targets" Condition=" '$(SkipSigning)' != 'true' "/> <PropertyGroup Condition="'$(Shipping)' == 'true'"> <GetSymbolsToIndexDependsOn Condition="'$(GetSymbolsToIndexDependsOn)' == ''">GetSymbolsToIndexDefault</GetSymbolsToIndexDependsOn> <SymbolTargetsToGetPdbs Condition="'$(SymbolTargetsToGetPdbs)' == ''">GetDebugSymbolsProjectOutput</SymbolTargetsToGetPdbs> </PropertyGroup> <ImportGroup Condition=" '$(PackProject)' == 'true' AND '$(NuGetBuildTasksPackTargets)' != '' "> <Import Project="$(NuGetBuildTasksPackTargets)" /> </ImportGroup> <!-- Readme file in shipping packages --> <PropertyGroup Condition=" '$(PackProject)' == 'true' "> <PackageReadmeFile>README.md</PackageReadmeFile> </PropertyGroup> <PropertyGroup Condition=" '$(PackProject)' != 'true' "> <NoWarn>$(NoWarn);CS0419;CS1570;CS1572;CS1573;CS1574;CS1584;CS1587;CS1591</NoWarn> </PropertyGroup> <ItemGroup Condition=" '$(PackProject)' == 'true' "> <None Include="$(MSBuildThisFileDirectory)..\icon.png" Pack="true" PackagePath="\" Visible="false" /> <None Include="$(MSBuildProjectDirectory)\README.md" Pack="true" PackagePath="\"/> </ItemGroup> <!-- Don't use PublicApiAnalyzer on source-build .NET --> <PropertyGroup Condition=" '$(DotNetBuildSourceOnly)' == 'true' "> <UsePublicApiAnalyzer>false</UsePublicApiAnalyzer> </PropertyGroup> <!-- Projects we pack become public APIs that others can use --> <PropertyGroup Condition=" '$(DotNetBuildSourceOnly)' != 'true' and '$(PackProject)' == 'true' "> <UsePublicApiAnalyzer Condition=" '$(UsePublicApiAnalyzer)' == '' " >true</UsePublicApiAnalyzer> </PropertyGroup> <Target Name="UnknownUsePublicApiAnalyzerValue" AfterTargets="Restore" Condition=" '$(UsePublicApiAnalyzer)' != '' and '$(UsePublicApiAnalyzer)' != 'true' and '$(UsePublicApiAnalyzer)' != 'false' and '$(UsePublicApiAnalyzer)' != 'perTfm' "> <Error Text="Unknown/Unsupported value for UsePublicApiAnalyzer: $(UsePublicApiAnalyzer)" /> </Target> <!-- Test Projects --> <ImportGroup Condition=" '$(TestProject)' == 'true' "> <Import Project="test.targets" /> </ImportGroup> <!-- Allow WPF projects to run under NETCore SDK --> <!-- Errors occur if the output path is not set correctly --> <PropertyGroup Condition=" '$(NETCoreWPFProject)' == 'true' "> <BaseOutputPath>bin\</BaseOutputPath> <OutputPath>bin\$(Configuration)</OutputPath> <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> </PropertyGroup> <!-- These are needed because currently a VSIX project cannot reference a net core project that multi targets. This is a hack for building the VSIX. It's because all these targets are available in the inner build, while the VSIX project is non netcore, and isn't aware of inner/outer builds. --> <Target Name="BuiltProjectOutputGroupDependencies" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" /> <Target Name="BuiltProjectOutputGroup" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" /> <Target Name="GetCopyToOutputDirectoryItems" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" /> <Target Name="SatelliteDllsProjectOutputGroup" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" /> <Target Name="DebugSymbolsProjectOutputGroup" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" /> <!-- ============================================================ TestProject Runs tests on the current project if it is a test project. ============================================================ --> <Target Name="TestProject" Condition=" '$(TestProject)' == 'true' " DependsOnTargets="VSTest"> <Message Text="Tested project $(MSBuildProjectName)" Importance="high" /> </Target> <!-- ============================================================ PackProjects This must be called after building. The dependency on build does not exist to improve perf. ============================================================ --> <Target Name="PackProjects" Condition=" '$(PackProject)' == 'true' "> <!-- Run pack on the project --> <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Pack" Properties="Configuration=$(Configuration); PackageOutputPath=$(NupkgOutputDirectory); IncludeSymbols=true; NoBuild=true;"> </MSBuild> </Target> <!-- ============================================================ _IsProjectNeedsPack Verify if the project needs to be packed. ============================================================ --> <Target Name="_IsProjectNeedsPack" Returns="@(PackProjects)"> <ItemGroup Condition="'$(PackProject)' == 'true'"> <PackProjects Include="$(MSBuildProjectFullPath)"> </PackProjects> </ItemGroup> </Target> <!-- ============================================================ GetSymbolsToIndex - depends on targets that gather symbols that need to be indexed on the symbol server. ============================================================ --> <Target Name="GetSymbolsToIndex" DependsOnTargets="$(GetSymbolsToIndexDependsOn)" Returns="@(SymbolFilesToIndex)" /> <Target Name="GetSymbolsToIndexDefault" DependsOnTargets="GetTargetFrameworkSet" Returns="@(SymbolFilesToIndex)" Condition=" '$(Shipping)' == 'true' "> <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="$(SymbolTargetsToGetPdbs)" Properties="TargetFramework=%(ProjectTargetFrameworkEntries.Identity); BuildProjectReferences=false;"> <Output TaskParameter="TargetOutputs" ItemName="SymbolFilesToIndex" /> </MSBuild> </Target> <Target Name="GetXPLATProject" Returns="@(XPLATProjects)"> <ItemGroup Condition="'$(XPLATProject)' == 'true'"> <XPLATProjects Include="$(MSBuildProjectFullPath)"> </XPLATProjects> </ItemGroup> </Target> <Target Name="GetDebugSymbolsProjectOutput" DependsOnTargets="DebugSymbolsProjectOutputGroup" Returns="@(PdbsToIndex)"> <ItemGroup> <PdbsToIndex Include="@(DebugSymbolsProjectOutputGroupOutput->'%(FinalOutputPath)')"/> </ItemGroup> </Target> <!-- ============================================================ GetLocalizedFiles - gathers the list of files that have been localized from each project ============================================================ --> <!--Target is invoked by build\build.proj\MoveLocalizedFilesToLocalizedArtifacts to get all the localized files from all projects--> <Target Name="GetNetCoreLocalizedFilesInProjectOutputPath" Returns="@(_LocalizedNetCoreDllsWithRelativeTargetPath)" Condition=" '$(PackProject)' == 'true' "> <ItemGroup> <_LocalizedDllsNetCoreApp Include="$(OutputPath)$(NETCoreTargetFramework)\**\$(AssemblyName).resources.dll"/> <_LocalizedDllsNetCoreApp Include="$(OutputPath)$(LatestNETCoreTargetFramework)\**\$(AssemblyName).resources.dll"/> <_LocalizedDllsNetStandard Include="$(OutputPath)$(NetStandardVersion)\**\$(AssemblyName).resources.dll"/> <_LocalizedNetCoreDllsWithRelativeTargetPath Include="@(_LocalizedDllsNetCoreApp)" Condition=" '@(_LocalizedDllsNetCoreApp)' != '' "> <RelativeTargetPath>$(NetStandardVersion)\%(_LocalizedDllsNetCoreApp.RecursiveDir)%(_LocalizedDllsNetCoreApp.FileName)%(_LocalizedDllsNetCoreApp.Extension)</RelativeTargetPath> </_LocalizedNetCoreDllsWithRelativeTargetPath> <_LocalizedNetCoreDllsWithRelativeTargetPath Include="@(_LocalizedDllsNetStandard)" Condition=" '@(_LocalizedDllsNetStandard)' != '' "> <RelativeTargetPath>$(NetStandardVersion)\%(_LocalizedDllsNetStandard.RecursiveDir)%(_LocalizedDllsNetStandard.FileName)%(_LocalizedDllsNetStandard.Extension)</RelativeTargetPath> </_LocalizedNetCoreDllsWithRelativeTargetPath> </ItemGroup> </Target> <!-- ============================================================ GetTestAssemblies ============================================================ --> <Target Name="GetTestAssemblies" DependsOnTargets="Build;GetTargetFrameworkSet" Condition=" '$(TestProject)' == 'true' AND '$(SkipTests)' != 'true' " Returns="@(TestAssemblyPath)"> <Message Text="Discovering test assemblies for $(AssemblyName)" Importance="high" /> <!-- Execute find for all frameworks --> <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="GetTestAssembliesInner" Properties="TargetFramework=%(ProjectTargetFrameworkEntries.Identity); Configuration=$(Configuration);"> <Output TaskParameter="TargetOutputs" ItemName="TestAssemblyPath" /> </MSBuild> </Target> <!-- ============================================================ GetTestAssembliesInner ============================================================ --> <Target Name="GetTestAssembliesInner" Returns="@(TestAssemblyPath)"> <PropertyGroup> <TestAssemblyRelativePath>$(OutputPath)$(AssemblyName).dll</TestAssemblyRelativePath> </PropertyGroup> <ConvertToAbsolutePath Paths="$(TestAssemblyRelativePath)"> <Output TaskParameter="AbsolutePaths" PropertyName="AbsoluteTestAssemblyPath"/> </ConvertToAbsolutePath> <ItemGroup> <TestAssemblyPath Include="$(AbsoluteTestAssemblyPath)"> <IsDesktop Condition=" '$(TargetFramework)' == '$(NETFXTargetFramework)' ">true</IsDesktop> <IsCore Condition=" '$(TargetFramework)' != '$(NETFXTargetFramework)' ">true</IsCore> </TestAssemblyPath> </ItemGroup> </Target> <!-- ============================================================ GetTargetFrameworkSet get all target frameworks ============================================================ --> <Target Name="GetTargetFrameworkSet" Returns="@(ProjectTargetFrameworkEntries)"> <!-- Find all frameworks to run on --> <ItemGroup> <ProjectTargetFrameworkEntries Include="$(TargetFramework);$(TargetFrameworks)" /> </ItemGroup> </Target> <!-- ============================================================ EnsureNewtonsoftJsonVersion ensures that the resolved version of Newtonsoft.Json is the version that ships with VS/.NET Core SDK ============================================================ --> <Target Name="EnsureNewtonsoftJsonVersion" AfterTargets="ResolveAssemblyReferences"> <Error Text="Newtonsoft.Json must be version $(NewtonsoftJsonPackageVersion) but resolved %(Reference.NuGetPackageVersion)" Condition=" %(Reference.NuGetPackageId) == 'Newtonsoft.Json' AND %(Reference.NuGetPackageVersion) != '$(NewtonsoftJsonPackageVersion)' " /> </Target> <Target Name="GetAllTargetFrameworks"> <PropertyGroup> <EffectiveFramework Condition=" '$(TargetFrameworks)' != '' ">$(TargetFrameworks)</EffectiveFramework> <EffectiveFramework Condition=" '$(EffectiveFramework)' == '' ">$(TargetFramework)</EffectiveFramework> </PropertyGroup> <Message Text="$(MSBuildProjectFile) = $(EffectiveFramework)" Importance="High" /> </Target> </Project>