/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
Directory.Build.targets
127 строк
7 KB
Clint Rutkas
Fixing a WindowBase warning during compile (#49049)
28 июл 2026, 17:45
Не верифицирован
28 июл 2026, 17:45
7afcb8c
Код
Авторство
О чём код?
<Project> <Sdk Name="Microsoft.Build.CopyOnWrite" Version="1.0.282" /> <Import Project="$(MSBuildCachePackageRoot)\build\$(MSBuildCachePackageName).targets" Condition="'$(MSBuildCacheEnabled)' == 'true'" /> <Import Project="$(MSBuildCacheSharedCompilationPackageRoot)\build\Microsoft.MSBuildCache.SharedCompilation.targets" Condition="'$(MSBuildCacheEnabled)' == 'true'" /> <!-- Onboarding guard: PowerToys has deeply nested source paths that exceed the legacy 260-character MAX_PATH limit. Without Windows long path support enabled, the build fails with cryptic "path too long" / "could not find file" errors that are hard for new contributors to diagnose. Detect the missing registry setting up front and emit a clear, actionable error before the confusing failures occur. - Covers both Visual Studio (Ctrl+Shift+B) and the command-line build scripts. - Runs only during real builds (skips design-time/IntelliSense passes). - Bypass with /p:SkipLongPathsCheck=true if you know what you're doing. See tools\build\setup-dev-environment.ps1 to enable everything automatically. --> <Target Name="EnsureLongPathsEnabled" BeforeTargets="PrepareForBuild" Condition="'$(DesignTimeBuild)' != 'true' and '$(SkipLongPathsCheck)' != 'true' and '$(OS)' == 'Windows_NT'"> <PropertyGroup> <_LongPathsEnabled>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem', 'LongPathsEnabled', null, RegistryView.Registry64))</_LongPathsEnabled> </PropertyGroup> <Error Condition="'$(_LongPathsEnabled)' != '1'" Code="PTLONGPATH" Text="Windows long path support is not enabled. PowerToys source paths exceed the 260-character MAX_PATH limit, so the build will fail with cryptic 'path too long' errors. Fix it by running (from an elevated PowerShell): .\tools\build\setup-dev-environment.ps1 -- or set HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled = 1 (DWORD) and restart Windows. To bypass this check, build with /p:SkipLongPathsCheck=true." /> </Target> <!-- Override ManifestTool to the x64 host tool under WindowsSdkDir for all projects once the SDK path is known. --> <PropertyGroup Label="ManifestToolOverride"> <ManifestTool Condition="Exists('$(WindowsSdkDir)bin\x64\mt.exe')">$(WindowsSdkDir)bin\x64\mt.exe</ManifestTool> </PropertyGroup> <!-- Auto-restore NuGet for native vcxproj (PackageReference) when building inside VS --> <Target Name="EnsureNuGetRestoreForVcxproj" BeforeTargets="PrepareForBuild" Condition=" '$(BuildingInsideVisualStudio)' == 'true' and '$(DesignTimeBuild)' != 'true' and '$(RestoreInProgress)' != 'true' and '$(MSBuildProjectExtension)' == '.vcxproj' and '$(RestoreProjectStyle)' == 'PackageReference' and '$(MSBuildProjectExtensionsPath)' != '' and !Exists('$(MSBuildProjectExtensionsPath)project.assets.json') "> <Message Importance="normal" Text="NuGet assets missing for $(MSBuildProjectName); running Restore...; IntDir=$(IntDir); BaseIntermediateOutputPath=$(BaseIntermediateOutputPath)" /> <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Restore" Properties="RestoreInProgress=true" BuildInParallel="false" /> </Target> <!-- The Microsoft.Web.WebView2 package's managed .targets unconditionally references the WPF wrapper (Microsoft.Web.WebView2.Wpf.dll) for every non-WinRT .NET project. That wrapper depends on WPF's WindowsBase, which only ships in the WPF profile of the WindowsDesktop reference pack. WinForms-only or plain projects therefore resolve WindowsBase to the 4.0.0.0 facade from Microsoft.NETCore.App, producing an MSB3277 conflict against the wrapper's 5.0.0.0 reference. A project that doesn't enable WPF can't use the WPF WebView2 control anyway, so drop that unused reference before RAR runs (WPF projects keep it). WinUI/WinAppSDK projects use the CsWinRT projection and never get this reference, so this is a no-op for them. --> <Target Name="RemoveUnusedWebView2WpfReference" BeforeTargets="ResolveAssemblyReferences" Condition="'$(UseWPF)' != 'true'"> <ItemGroup> <Reference Remove="@(Reference)" Condition="'%(Reference.Filename)' == 'Microsoft.Web.WebView2.Wpf'" /> </ItemGroup> </Target> <PropertyGroup Condition="'$(IgnoreExperimentalWarnings)' == 'true'"> <NoWarn>$(NoWarn);CS8305;SA1500;CA1852</NoWarn> </PropertyGroup> <!-- Skipped test projects when BuildTests=false: no-op build and remove references. This must be in targets (not props) so it runs AFTER the project file adds its items. --> <PropertyGroup Condition="'$(_IsSkippedTestProject)' == 'true'"> <BuildDependsOn /> <CoreBuildDependsOn /> <RebuildDependsOn /> </PropertyGroup> <!-- For C# projects: remove all items --> <ItemGroup Condition="'$(_IsSkippedTestProject)' == 'true' and '$(MSBuildProjectExtension)' == '.csproj'"> <PackageReference Remove="@(PackageReference)" /> <ProjectReference Remove="@(ProjectReference)" /> <Reference Remove="@(Reference)" /> <Compile Remove="@(Compile)" /> <Content Remove="@(Content)" /> <EmbeddedResource Remove="@(EmbeddedResource)" /> <None Remove="@(None)" /> <Using Remove="@(Using)" /> <GlobalUsing Remove="@(GlobalUsing)" /> </ItemGroup> <!-- For C++ projects (vcxproj): remove all compile/link items to prevent build --> <ItemGroup Condition="'$(_IsSkippedTestProject)' == 'true' and '$(MSBuildProjectExtension)' == '.vcxproj'"> <ClCompile Remove="@(ClCompile)" /> <ClInclude Remove="@(ClInclude)" /> <Link Remove="@(Link)" /> <Lib Remove="@(Lib)" /> <ProjectReference Remove="@(ProjectReference)" /> <None Remove="@(None)" /> <ResourceCompile Remove="@(ResourceCompile)" /> <Midl Remove="@(Midl)" /> </ItemGroup> <!-- Note: For C++ skipped test projects, build is effectively skipped by removing all compile items above. We don't define empty Build/Rebuild/Clean targets here because MSBuild Target definitions with Condition on the Target element still override the default targets even when condition is false. --> <!-- Clean up unused VC++ runtime DLLs that CopyCppRuntimeToOutputDir copies from the full VCRedist tree (MFC, C++ AMP, OpenMP). No PowerToys binary links against these — verified with dumpbin /dependents across all installed binaries. --> <Target Name="RemoveUnusedVCRuntimeDlls" AfterTargets="Build" Condition="'$(CopyCppRuntimeToOutputDir)' == 'true' and '$(MSBuildProjectExtension)' == '.vcxproj'"> <ItemGroup> <_UnusedVCRuntimeDlls Include="$(OutDir)mfc140*.dll" /> <_UnusedVCRuntimeDlls Include="$(OutDir)mfcm140*.dll" /> <_UnusedVCRuntimeDlls Include="$(OutDir)vcamp140*.dll" /> <_UnusedVCRuntimeDlls Include="$(OutDir)vcomp140*.dll" /> </ItemGroup> <Delete Files="@(_UnusedVCRuntimeDlls)" Condition="'@(_UnusedVCRuntimeDlls)' != ''" /> <Message Importance="normal" Text="Cleaned up unused VC runtime DLLs: @(_UnusedVCRuntimeDlls)" Condition="'@(_UnusedVCRuntimeDlls)' != ''" /> </Target> </Project>