Skip to content

Commit

Permalink
Remove NetCoreReference
Browse files Browse the repository at this point in the history
This removes the `NetCoreReference` infrastructure and replaces it with `DefaultReferenceExclusion` to remove the one problematic implicit reference to WindowsBase.

Manually picking references was blocking using System.Private.Windows.Core from the WinForms repo. Not having this also greatly simplifies the projects.

This also tweaks the solution to add folders docs and eng items.

Fixes dotnet#9168
  • Loading branch information
JeremyKuhne committed Oct 8, 2024
1 parent 88d6691 commit 9f69ed5
Show file tree
Hide file tree
Showing 61 changed files with 78 additions and 1,645 deletions.
6 changes: 1 addition & 5 deletions Documentation/LocalMarkupCompilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,4 @@ It can be enabled for a project by setting this:
In addition to these, care must be taken for the following:

- Use `<EmbeddedResource>` instead of `<Resource>`
- `PresentationBuildTask` will strip out `<Resource>` items during `_CompileTemporaryAssembly` phase. Using `EmbeddedResource` is equivalent (esp. in for `Xlf` based string resource generation with `Arcade.Sdk`) and will not be adversely affected by `PresentationBuildTasks` transformations.
- Always use `<NetCoreReference>` instead of implicitly acquiring the full set of `Microsoft.NetCore.App` references.
- `Microsoft.NetCore.App` contains a version `WindowsBase` that clashes with WPF's `WindowsBase` during markup compilation.
- To avoid this clash, we must always specify the references we need explicitly.
- Also, our code-base requires that all references be specified explicitly anyway to avoid inadvertent reference-creep to bug-fixes.
- `PresentationBuildTask` will strip out `<Resource>` items during `_CompileTemporaryAssembly` phase. Using `EmbeddedResource` is equivalent (esp. in for `Xlf` based string resource generation with `Arcade.Sdk`) and will not be adversely affected by `PresentationBuildTasks` transformations.
45 changes: 36 additions & 9 deletions Microsoft.Dotnet.Wpf.sln
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OSVersionHelper", "src\Micr
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PresentationNative", "src\Microsoft.DotNet.Wpf\redist\PresentationNative\PresentationNative.vcxproj", "{AF9084C3-BF37-4A56-A851-89F3BAE731B3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F3F4DFE8-A29C-4BA1-964D-954AB6732744}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.DotNet.Wpf", "Microsoft.DotNet.Wpf", "{C9ECC1A1-917F-43D3-B340-2035B4938507}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{34B64A4A-7C83-4F92-8C47-80E9FA10D660}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{A48B585E-6AB0-4F8D-8484-77F37CB44437}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Xaml.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\System.Xaml.Tests\System.Xaml.Tests.csproj", "{B2F2A89C-55C9-41B1-A645-0948609BD8BE}"
Expand All @@ -255,6 +249,41 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationFramework.Fluen
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationCore.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\PresentationCore.Tests\PresentationCore.Tests.csproj", "{A4377D3F-6BA1-4994-945C-88667993E4F3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "eng", "eng", "{92968783-2008-4A16-A823-6737224FEB9E}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
eng\WpfArcadeSdk\tools\Pbt.targets = eng\WpfArcadeSdk\tools\Pbt.targets
eng\WpfArcadeSdk\Sdk\Sdk.props = eng\WpfArcadeSdk\Sdk\Sdk.props
eng\WpfArcadeSdk\Sdk\Sdk.targets = eng\WpfArcadeSdk\Sdk\Sdk.targets
eng\WpfArcadeSdk\tools\SdkReferences.targets = eng\WpfArcadeSdk\tools\SdkReferences.targets
start-vs.cmd = start-vs.cmd
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentation", "{B90B3D18-1B80-4FAF-A8DF-146C4F930AF9}"
ProjectSection(SolutionItems) = preProject
Documentation\acceptance_criteria.md = Documentation\acceptance_criteria.md
Documentation\api-compat.md = Documentation\api-compat.md
Documentation\C++-notes.md = Documentation\C++-notes.md
Documentation\c++-private-tools.md = Documentation\c++-private-tools.md
Documentation\codegen.md = Documentation\codegen.md
Documentation\contributing.md = Documentation\contributing.md
Documentation\cycle-breakers.md = Documentation\cycle-breakers.md
Documentation\developer-guide.md = Documentation\developer-guide.md
Documentation\gen-api.md = Documentation\gen-api.md
Documentation\getting-started.md = Documentation\getting-started.md
Documentation\issue-guide.md = Documentation\issue-guide.md
Documentation\localization_untranslated_strings.md = Documentation\localization_untranslated_strings.md
Documentation\LocalMarkupCompilation.md = Documentation\LocalMarkupCompilation.md
Documentation\packaging.md = Documentation\packaging.md
Documentation\projects-and-assemblies.md = Documentation\projects-and-assemblies.md
Documentation\redistributables.md = Documentation\redistributables.md
Documentation\report-on-adding-new-property.md = Documentation\report-on-adding-new-property.md
Documentation\solution-and-project-configurations.md = Documentation\solution-and-project-configurations.md
Documentation\testing-in-helix.md = Documentation\testing-in-helix.md
Documentation\wpf.vsconfig = Documentation\wpf.vsconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -2106,9 +2135,7 @@ Global
{7EE0E965-7DA4-4A94-9441-801E8D2CC1CD} = {4557C5C6-10B1-475C-8279-5511955D1C29}
{3801B5AE-6871-4A72-B400-1F6ABCBF9045} = {7EE0E965-7DA4-4A94-9441-801E8D2CC1CD}
{AF9084C3-BF37-4A56-A851-89F3BAE731B3} = {DDED00A7-24FD-4AEF-B264-2150F0E59B4D}
{C9ECC1A1-917F-43D3-B340-2035B4938507} = {F3F4DFE8-A29C-4BA1-964D-954AB6732744}
{34B64A4A-7C83-4F92-8C47-80E9FA10D660} = {C9ECC1A1-917F-43D3-B340-2035B4938507}
{A48B585E-6AB0-4F8D-8484-77F37CB44437} = {34B64A4A-7C83-4F92-8C47-80E9FA10D660}
{A48B585E-6AB0-4F8D-8484-77F37CB44437} = {B0EFDB12-C931-4E7F-A6C2-D4AC111D7EDF}
{B2F2A89C-55C9-41B1-A645-0948609BD8BE} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9} = {5ACFB055-649D-4A01-98C2-B0BFE7E543D6}
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD} = {60F4058B-D35B-42D2-B276-D44B3AC579BD}
Expand Down
15 changes: 0 additions & 15 deletions eng/WpfArcadeSdk/tools/Pbt.targets
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@
-->
<EmbedUntrackedSources Condition="'$(InternalMarkupCompilation)'=='true'">false</EmbedUntrackedSources>
</PropertyGroup>
<!--
Internal PBT compilation requires that we use <NetCoreReference>
This is so that the copy of ref\WindowsBase.dll inherited from Microsoft.NetCore.App
does not make its way through to markup-compilation.
In addition to this, our codebase requires that all references to Microsoft.NetCore.App
be explicitly enumerated through the use of <NetCoreReference> to avoid inadvertent additions
to assembly references during code-changes.
-->
<ItemGroup Condition="'$(InternalMarkupCompilation)'=='true'">
<NetCoreReference Include="mscorlib" />
<NetCoreReference Include="System" />
<NetCoreReference Include="System.ComponentModel.TypeConverter" />
<NetCoreReference Include="System.Runtime" />
</ItemGroup>

<PropertyGroup Condition="'$(InternalMarkupCompilation)'=='true' And Exists('$(LocalMicrosoftWinFXTargets)')">
<PrepareResourceNamesDependsOn>
Expand Down
120 changes: 32 additions & 88 deletions eng/WpfArcadeSdk/tools/SdkReferences.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@
Version="$(MicrosoftPrivateWinformsVersion)"
ExcludeAssets="All"
GeneratePathProperty="True"
Condition="'$(MSBuildProjectExtension)'!='.vcxproj'
Condition="'$(MSBuildProjectExtension)' != '.vcxproj'
And '$(TargetFrameworkIdentifier)' == '.NETCoreApp'
And $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '3.0'))
And '$(NoAutoMicrosoftPrivateWinformsReference)'!='true'"/>

<!--
When @(NetCoreReference) is non-empty, exclude all assets (ExcludeAssets = All) and re-add them in
ResolveMicrosoftNetCoreAppReferences target
-->
<PackageReference Update="Microsoft.NETCore.App"
GeneratePathProperty="true"
ExcludeAssets="All"
Condition="'@(NetCoreReference)'!='' And '$(DoNotLimitMicrosoftNetCoreReferences)'!='true' And '$(MSBuildProjectExtension)'!='.vcxproj' And '$(DisableImplicitFrameworkReferences)' != 'true' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
And '$(NoAutoMicrosoftPrivateWinformsReference)' != 'true'"/>

<PackageReference Update="Microsoft.NETCore.App"
GeneratePathProperty="true"
Condition="('@(NetCoreReference)'=='' Or '$(DoNotLimitMicrosoftNetCoreReferences)' == 'true') And '$(MSBuildProjectExtension)'!='.vcxproj' And '$(DisableImplicitFrameworkReferences)' != 'true' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
Condition="'$(MSBuildProjectExtension)'!='.vcxproj' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
</ItemGroup>

<Target Name="GeneratePathPropertyforMicrosoftWindowsDesktopApp"
Expand All @@ -40,82 +31,6 @@
</ResolveAssemblyReferencesDependsOn>
</PropertyGroup>


<Target
Name="LimitNetCoreAppReferences"
AfterTargets="ResolveTargetingPackAssets;ResolveTargetingPacks"
Returns="@(Reference)"
Condition="'@(NetCoreReference)' != '' And '@(Reference)' != ''">
<!--
Example
<NetCoreReference Include="Microsoft.CSharp" />
-->

<!--
Save Microsoft.NETCore.App.Ref assemblies, and remove those from @(Reference)
-->
<ItemGroup>
<_netCoreAppSdkReference Remove="@(_netCoreAppSdkReference)" />
<_netCoreAppSdkReference Include="@(Reference)"
Condition="'%(Reference.NuGetPackageId)'=='Microsoft.NETCore.App.Ref'">
<OriginalPath>%(Reference.Identity)</OriginalPath>
</_netCoreAppSdkReference>

<Reference Remove="@(_netCoreAppSdkReference)" />
</ItemGroup>

<ItemGroup>
<_netCoreAppReferences Remove="@(_netCoreAppReferences)" />
</ItemGroup>
<FilterItem1ByItem2 Item1="@(_netCoreAppSdkReference->'%(FileName)')"
Item2="@(NetCoreReference)"
Metadata2="Identity"
PreserveItem1Metadata="true">
<Output ItemName="_netCoreAppReferences" TaskParameter="Result" />
</FilterItem1ByItem2>

<ItemGroup>
<Reference Include="@(_netCoreAppReferences->'%(OriginalPath)')" />
</ItemGroup>
</Target>

<Target Name="LimitWindowsDesktopAppReferences"
AfterTargets="ResolveTargetingPacks;ResolveTargetingPackAsssets"
Returns="@(Reference)"
Condition="'@(WindowsDesktopReference)'!='' and '@(Reference)' != ''">
<!--
Example
<WindowsDesktopReference Include="PresentationCore" />
-->

<!--
Save Microsoft.WindowsDesktop.App.Ref assemblies, and remove those from @(Reference)
-->
<ItemGroup>
<_windowsDesktopAppSdkReference Remove="@(_windowsDesktopAppSdkReference)" />
<_windowsDesktopAppSdkReference Include="@(Reference)"
Condition="'%(Reference.NuGetPackageId)'=='Microsoft.WindowsDesktop.App.Ref'">
<OriginalPath>%(Reference.Identity)</OriginalPath>
</_windowsDesktopAppSdkReference>

<Reference Remove="@(_windowsDesktopAppSdkReference)" />
</ItemGroup>

<ItemGroup>
<_windowsDesktopAppReferences Remove="@(_windowsDesktopAppReferences)" />
</ItemGroup>
<FilterItem1ByItem2 Item1="@(_windowsDesktopAppSdkReference->'%(FileName)')"
Item2="@(WindowsDesktopReference)"
Metadata2="Identity"
PreserveItem1Metadata="true">
<Output ItemName="_windowsDesktopAppReferences" TaskParameter="Result" />
</FilterItem1ByItem2>

<ItemGroup>
<Reference Include="@(_windowsDesktopAppReferences->'%(OriginalPath)')" />
</ItemGroup>
</Target>

<Target
Name="ResolveMicrosoftDotNetWpfGitHubReferences"
Returns="@(ReferencePath)"
Expand Down Expand Up @@ -210,4 +125,33 @@
</Reference>
</ItemGroup>
</Target>

<ItemGroup>
<!-- We always want to use the local WindowsBase, not the one coming from the .NET runtime. -->
<DefaultReferenceExclusion Include="WindowsBase"/>
</ItemGroup>

<!--
Allows excluding specific .NET runtime libraries from being implicitly referenced.
For example, to exclude WindowsBase from being implicitly referenced, add the following to your project file:
<DefaultReferenceExclusion>
<MicrosoftPrivateWinFormsReference Include="WindowsBase" />
</DefaultReferenceExclusion>
-->
<Target Name="FilterImplicitAssemblyReferences"
Condition="'@(DefaultReferenceExclusion)' != ''"
DependsOnTargets="ResolveProjectReferences"
AfterTargets="ResolveTargetingPackAssets">
<ItemGroup>
<_referenceExclusion Include="@(DefaultReferenceExclusion)">
<AssemblyName>%(DefaultReferenceExclusion.Identity)</AssemblyName>
<FrameworkReferenceName>Microsoft.NETCore.App</FrameworkReferenceName>
<ExternallyResolved>true</ExternallyResolved>
</_referenceExclusion>

<Reference Remove="@(_referenceExclusion)"
MatchOnMetadata="AssemblyName;FrameworkReferenceName;ExternallyResolved"/>
</ItemGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@
</PropertyGroup>

<PropertyGroup>

<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>

<ItemGroup>
<Compile Include="System.Windows.Controls.DocumentViewer.cs" />
<Compile Include="System.Windows.Controls.ToolBar.cs" />
</ItemGroup>

<ItemGroup>
<NetCoreReference Include="System.Runtime" />
<NetCoreReference Include="System.Resources.ResourceManager" />
<NetCoreReference Include="System.Runtime.InteropServices" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,13 @@
</PropertyGroup>

<PropertyGroup>

<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>

<ItemGroup>
<Compile Include="PresentationFramework.cs" />
</ItemGroup>

<ItemGroup>
<NetCoreReference Include="System.Collections" />
<NetCoreReference Include="System.Collections.NonGeneric" />
<NetCoreReference Include="System.Collections.Specialized" />
<NetCoreReference Include="System.ComponentModel" />
<NetCoreReference Include="System.ComponentModel.EventBasedAsync" />
<NetCoreReference Include="System.ComponentModel.Primitives" />
<NetCoreReference Include="System.ComponentModel.TypeConverter" />
<NetCoreReference Include="System.Dynamic.Runtime" />
<NetCoreReference Include="System.Linq.Expressions" />
<NetCoreReference Include="System.Net.Primitives" />
<NetCoreReference Include="System.Net.Requests" />
<NetCoreReference Include="System.Net.WebHeaderCollection" />
<NetCoreReference Include="System.ObjectModel" />
<NetCoreReference Include="System.Runtime" />
<NetCoreReference Include="System.Resources.ResourceManager" />
<NetCoreReference Include="System.Runtime.Extensions" />
<NetCoreReference Include="System.Runtime.InteropServices" />
<NetCoreReference Include="System.Xml" />
<NetCoreReference Include="System.Xml.Document" />
<NetCoreReference Include="System.Xml.ReaderWriter" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(WpfSourceDir)PresentationCore\PresentationCore.csproj" />
<ProjectReference Include="$(WpfSourceDir)UIAutomation\UIAutomationProvider\UIAutomationProvider.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</PropertyGroup>

<PropertyGroup>

<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>

Expand All @@ -26,29 +25,6 @@
<Compile Include="System.Windows.Documents.Serialization.SerializerWriterCollator.cs" />
</ItemGroup>

<ItemGroup>
<NetCoreReference Include="System.Collections" />
<NetCoreReference Include="System.Collections.NonGeneric" />
<NetCoreReference Include="System.Collections.Specialized" />
<NetCoreReference Include="System.ComponentModel" />
<NetCoreReference Include="System.ComponentModel.EventBasedAsync" />
<NetCoreReference Include="System.ComponentModel.Primitives" />
<NetCoreReference Include="System.ComponentModel.TypeConverter" />
<NetCoreReference Include="System.Dynamic.Runtime" />
<NetCoreReference Include="System.Linq.Expressions" />
<NetCoreReference Include="System.Net.Primitives" />
<NetCoreReference Include="System.Net.Requests" />
<NetCoreReference Include="System.Net.WebHeaderCollection" />
<NetCoreReference Include="System.ObjectModel" />
<NetCoreReference Include="System.Runtime" />
<NetCoreReference Include="System.Resources.ResourceManager" />
<NetCoreReference Include="System.Runtime.Extensions" />
<NetCoreReference Include="System.Runtime.InteropServices" />
<NetCoreReference Include="System.Xml" />
<NetCoreReference Include="System.Xml.Document" />
<NetCoreReference Include="System.Xml.ReaderWriter" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(WpfSourceDir)PresentationCore\PresentationCore.csproj" />
<ProjectReference Include="$(WpfSourceDir)System.Xaml\System.Xaml.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,13 @@
</PropertyGroup>

<PropertyGroup>

<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>

<ItemGroup>
<Compile Include="PresentationFramework.cs" />
</ItemGroup>

<ItemGroup>
<NetCoreReference Include="System.Collections" />
<NetCoreReference Include="System.Collections.NonGeneric" />
<NetCoreReference Include="System.Collections.Specialized" />
<NetCoreReference Include="System.ComponentModel" />
<NetCoreReference Include="System.ComponentModel.EventBasedAsync" />
<NetCoreReference Include="System.ComponentModel.Primitives" />
<NetCoreReference Include="System.ComponentModel.TypeConverter" />
<NetCoreReference Include="System.Dynamic.Runtime" />
<NetCoreReference Include="System.Linq.Expressions" />
<NetCoreReference Include="System.Net.Primitives" />
<NetCoreReference Include="System.Net.Requests" />
<NetCoreReference Include="System.Net.WebHeaderCollection" />
<NetCoreReference Include="System.ObjectModel" />
<NetCoreReference Include="System.Runtime" />
<NetCoreReference Include="System.Resources.ResourceManager" />
<NetCoreReference Include="System.Runtime.Extensions" />
<NetCoreReference Include="System.Runtime.InteropServices" />
<NetCoreReference Include="System.Xml" />
<NetCoreReference Include="System.Xml.Document" />
<NetCoreReference Include="System.Xml.ReaderWriter" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(WpfSourceDir)PresentationCore\PresentationCore.csproj" />
<ProjectReference Include="$(WpfSourceDir)System.Xaml\System.Xaml.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</PropertyGroup>

<PropertyGroup>

<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>

Expand All @@ -22,12 +21,6 @@
<Compile Include="$(WpfSharedDir)RefAssemblyAttrs.cs" />
</ItemGroup>

<ItemGroup>
<NetCoreReference Include="System.Runtime" />
<NetCoreReference Include="System.Resources.ResourceManager" />
<NetCoreReference Include="System.Runtime.InteropServices" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(WpfSourceDir)PresentationCore\PresentationCore.csproj" />
<ProjectReference Include="$(WpfSourceDir)System.Xaml\System.Xaml.csproj" />
Expand Down
Loading

0 comments on commit 9f69ed5

Please sign in to comment.