/ Directory.Build.props
Directory.Build.props
1 <Project> 2 <PropertyGroup> 3 <RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot> 4 </PropertyGroup> 5 <Import Project="$(RepoRoot)src\Version.props" /> 6 <PropertyGroup> 7 <Copyright>Copyright (C) Microsoft Corporation. All rights reserved.</Copyright> 8 <AssemblyCopyright>Copyright (C) Microsoft Corporation. All rights reserved.</AssemblyCopyright> 9 <AssemblyProduct>PowerToys</AssemblyProduct> 10 <AssemblyCompany>Microsoft Corp.</AssemblyCompany> 11 <Company>Microsoft Corporation</Company> 12 <Authors>Microsoft Corporation</Authors> 13 <Product>PowerToys</Product> 14 <NeutralLanguage>en-US</NeutralLanguage> 15 <Platforms>x64;ARM64</Platforms> 16 <PackageTags>PowerToys</PackageTags> 17 <EnableNETAnalyzers>true</EnableNETAnalyzers> 18 <AnalysisMode>Recommended</AnalysisMode> 19 <_SkipUpgradeNetAnalyzersNuGetWarning>true</_SkipUpgradeNetAnalyzersNuGetWarning> 20 <NuGetAuditMode>direct</NuGetAuditMode> 21 <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion> <!-- Don't add source revision hash to the product version of binaries. --> 22 <PlatformTarget>$(Platform)</PlatformTarget> 23 </PropertyGroup> 24 25 <!-- 26 Completely skip building test projects when BuildTests=false (e.g., Release pipeline). 27 This avoids InternalsVisibleTo/signing issues by not compiling test code at all. 28 Match: projects ending in Test, Tests, UnitTests, UITests, FuzzTests, or in a folder named Tests. 29 Also matches projects starting with UnitTests- (e.g., UnitTests-CommonLib). 30 Also removes all PackageReference/ProjectReference to prevent NuGet restore and dependency builds. 31 Note: Checking both 'false' and 'False' to handle YAML boolean serialization. 32 --> 33 <PropertyGroup Condition="'$(BuildTests)' == 'false' or '$(BuildTests)' == 'False'"> 34 <_ProjectName>$(MSBuildProjectName)</_ProjectName> 35 <!-- Match any project ending with "Test" or "Tests" (covers UnitTests, UITests, FuzzTests, etc.) --> 36 <_IsSkippedTestProject Condition="$(_ProjectName.EndsWith('Test'))">true</_IsSkippedTestProject> 37 <_IsSkippedTestProject Condition="$(_ProjectName.EndsWith('Tests'))">true</_IsSkippedTestProject> 38 <!-- Match projects starting with UnitTests- or UITest- prefix --> 39 <_IsSkippedTestProject Condition="$(_ProjectName.StartsWith('UnitTests-'))">true</_IsSkippedTestProject> 40 <_IsSkippedTestProject Condition="$(_ProjectName.StartsWith('UITest-'))">true</_IsSkippedTestProject> 41 <!-- Match projects in a Tests folder --> 42 <_IsSkippedTestProject Condition="$(MSBuildProjectDirectory.Contains('\Tests\'))">true</_IsSkippedTestProject> 43 </PropertyGroup> 44 45 <PropertyGroup Condition="'$(_IsSkippedTestProject)' == 'true'"> 46 <EnableDefaultItems>false</EnableDefaultItems> 47 <EnableDefaultCompileItems>false</EnableDefaultCompileItems> 48 <GenerateAssemblyInfo>false</GenerateAssemblyInfo> 49 <GenerateGlobalUsings>false</GenerateGlobalUsings> 50 <ImplicitUsings>disable</ImplicitUsings> 51 <!-- Disable all code analysis for skipped test projects --> 52 <EnableNETAnalyzers>false</EnableNETAnalyzers> 53 <RunAnalyzers>false</RunAnalyzers> 54 <RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild> 55 <TreatWarningsAsErrors>false</TreatWarningsAsErrors> 56 </PropertyGroup> 57 58 <PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'"> 59 <Version>$(Version).0</Version> 60 <RepositoryUrl>https://github.com/microsoft/PowerToys</RepositoryUrl> 61 <RepositoryType>GitHub</RepositoryType> 62 <TreatWarningsAsErrors>true</TreatWarningsAsErrors> 63 </PropertyGroup> 64 65 <PropertyGroup> 66 <_PropertySheetDisplayName>PowerToys.Root.Props</_PropertySheetDisplayName> 67 <ForceImportBeforeCppProps>$(RepoRoot)Cpp.Build.props</ForceImportBeforeCppProps> 68 </PropertyGroup> 69 70 71 <ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(_IsSkippedTestProject)' != 'true'"> 72 <PackageReference Include="StyleCop.Analyzers"> 73 <PrivateAssets>all</PrivateAssets> 74 <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 75 </PackageReference> 76 <Compile Include="$(RepoRoot)src\codeAnalysis\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" /> 77 <AdditionalFiles Include="$(RepoRoot)src\codeAnalysis\StyleCop.json" Link="StyleCop.json" /> 78 79 <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers"> 80 <PrivateAssets>all</PrivateAssets> 81 <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 82 </PackageReference> 83 </ItemGroup> 84 85 <!-- Add ability to run tests via "msbuild /t:Test" --> 86 <!-- 87 Work around an MSBuild bug where Microsoft.Common.Test.targets is missing from the Arm64 installation. 88 See: https://github.com/dotnet/msbuild/pull/9984 89 NB 1: This means that using "/t:Test" is not supported for Arm64 builds and tests will need to be run in an alternate way, 90 eg running tests in VS or invoking vstest.console directly. 91 NB 2: <Sdk> elements do not support conditions, so this is also being worked around. 92 Once the change referenced above is fixed, the ImportGroup below can be replaced with: 93 <Sdk Name="Microsoft.Build.RunVSTest" Version="1.0.319" /> 94 --> 95 <ImportGroup Condition="'$(PROCESSOR_ARCHITECTURE)' != 'ARM64'"> 96 <Import Project="Sdk.props" Sdk="Microsoft.Build.RunVSTest" Version="1.0.319" /> 97 <Import Project="Sdk.targets" Sdk="Microsoft.Build.RunVSTest" Version="1.0.319" /> 98 </ImportGroup> 99 <PropertyGroup> 100 <VSTestLogger>trx</VSTestLogger> 101 <!-- 102 RunVSTest by default uses %VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe, 103 but some of the CI scenarios don't define %VSINSTALLDIR%, so be explicit about where to look for vstest. 104 Note: $(VsInstallRoot) is a built-in MSBuild property, so should always be defined. 105 --> 106 <VSTestToolPath>$(VsInstallRoot)\Common7\IDE\CommonExtensions\Microsoft\TestWindow</VSTestToolPath> 107 <!-- No arm64 agents to run the tests. --> 108 <RunVSTest Condition="'$(Platform)' == 'ARM64'">false</RunVSTest> 109 </PropertyGroup> 110 111 <!-- MSBuildCache --> 112 <PropertyGroup> 113 <!-- Off by default --> 114 <MSBuildCacheEnabled Condition="'$(MSBuildCacheEnabled)' == ''">false</MSBuildCacheEnabled> 115 116 <!-- In Azure pipelines, use Pipeline Caching as the cache storage backend. Otherwise, use the local cache. --> 117 <MSBuildCachePackageName Condition="'$(TF_BUILD)' != ''">Microsoft.MSBuildCache.AzurePipelines</MSBuildCachePackageName> 118 <MSBuildCachePackageName Condition="'$(MSBuildCachePackageName)' == ''">Microsoft.MSBuildCache.Local</MSBuildCachePackageName> 119 </PropertyGroup> 120 121 <PropertyGroup Condition="'$(MSBuildCacheEnabled)' == 'true'"> 122 <!-- Disable when running in a pipeline as the time to upload or download the massive .pch/.pchast to the cache is greater than the savings they provide. --> 123 <UsePrecompiledHeaders Condition="'$(TF_BUILD)' != ''">false</UsePrecompiledHeaders> 124 125 <!-- Change this to bust the cache --> 126 <MSBuildCacheCacheUniverse Condition="'$(MSBuildCacheCacheUniverse)' == ''">202408150737</MSBuildCacheCacheUniverse> 127 128 <!-- 129 Visual Studio telemetry reads various ApplicationInsights.config files and other files after the project is finished, likely in a detached process. 130 This is acceptable and should not impact cache correctness. 131 --> 132 <MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns> 133 $(MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns); 134 \**\ApplicationInsights.config; 135 $(LocalAppData)\Microsoft\VSApplicationInsights\**; 136 $(LocalAppData)\Microsoft\Windows\INetCache\**; 137 A:\; 138 E:\; 139 $(windir)\**; 140 </MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns> 141 142 <!-- Unit tests of low-priv processes, eg the preview handler tests, may log to this location. --> 143 <MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns> 144 $(MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns); 145 $(USERPROFILE)\AppData\LocalLow\Microsoft\PowerToys\**; 146 </MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns> 147 148 <!-- 149 This repo uses a common output directory with many projects writing duplicate outputs. Allow everything, but note this costs some performance in the form of requiring 150 the cache to use copies instead of hardlinks when pulling from cache. 151 --> 152 <MSBuildCacheIdenticalDuplicateOutputPatterns>$(MSBuildCacheIdenticalDuplicateOutputPatterns);**</MSBuildCacheIdenticalDuplicateOutputPatterns> 153 154 <!-- version of MSBuildCache is not part of the cache key --> 155 <PackagesConfigFile>$(MSBuildThisFileDirectory)packages.config</PackagesConfigFile> 156 <MSBuildCacheIgnoredInputPatterns>$(MSBuildCacheIgnoredInputPatterns);$(PackagesConfigFile)</MSBuildCacheIgnoredInputPatterns> 157 </PropertyGroup> 158 159 <PropertyGroup Condition="'$(MSBuildCacheEnabled)' == 'true' and '$(MSBuildCachePackageRoot)' == ''"> 160 <PackagesConfigContents>$([System.IO.File]::ReadAllText("$(PackagesConfigFile)"))</PackagesConfigContents> 161 <MSBuildCachePackageVersion>$([System.Text.RegularExpressions.Regex]::Match($(PackagesConfigContents), 'Microsoft.MSBuildCache.*?version="(.*?)"').Groups[1].Value)</MSBuildCachePackageVersion> 162 <MSBuildCachePackageRoot>$(MSBuildThisFileDirectory)packages\$(MSBuildCachePackageName).$(MSBuildCachePackageVersion)</MSBuildCachePackageRoot> 163 <MSBuildCacheSharedCompilationPackageRoot>$(MSBuildThisFileDirectory)packages\Microsoft.MSBuildCache.SharedCompilation.$(MSBuildCachePackageVersion)</MSBuildCacheSharedCompilationPackageRoot> 164 </PropertyGroup> 165 166 <ImportGroup Condition="'$(MSBuildCacheEnabled)' == 'true'"> 167 <Import Project="$(MSBuildCachePackageRoot)\build\$(MSBuildCachePackageName).props" /> 168 <Import Project="$(MSBuildCacheSharedCompilationPackageRoot)\build\Microsoft.MSBuildCache.SharedCompilation.props" /> 169 </ImportGroup> 170 </Project>