Skip to content

Commit

Permalink
Use live runtime references for vcxproj
Browse files Browse the repository at this point in the history
Fixes #9490
Unblocks dotnet/sdk#43015

When building wpf inside the VMR, a 10.0.100 SDK is used. WPF currently still targets net9.0. As WPF directly depends on runtime, it already uses 10.0.0-alpha versions of the targeting and runtime packs for managed projects.

Enable this for vcxprojs as well so that the host packages can also be restored from the flowing runtime dependency.

Fixes errors like these:

> The Apphost pack is not installed and NuGet package restore is not supported. Upgrade Visual Studio, remove global.json if it specifies a certain SDK version, and uninstall the newer SDK. For more options visit   https://aka.ms/targeting-apphost-pack-missing  Pack Type:Apphost, Pack directory: D:\a\_work\1\vmr\.dotnet\packs\Microsoft.NETCore.App.Host.win-x64, targetframework: net9.0, Pack PackageId: Microsoft.NETCore.App.Host.win-x64, Pack Package Version: 9.0.0-rc.2.24473.5
  • Loading branch information
ViktorHofer committed Nov 6, 2024
1 parent 3a1f918 commit 601f3c5
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 246 deletions.
15 changes: 0 additions & 15 deletions eng/Tools.props

This file was deleted.

1 change: 1 addition & 0 deletions eng/WpfArcadeSdk/tools/RuntimeFrameworkReference.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!-- workaround for package downgrade in Microsoft.NetCore.Platforms -->
<PropertyGroup>
<DisableImplicitNETCorePlatformsReference>true</DisableImplicitNETCorePlatformsReference>
<EnableManagedPackageReferenceSupport>true</EnableManagedPackageReferenceSupport>
</PropertyGroup>

</Project>
65 changes: 1 addition & 64 deletions eng/WpfArcadeSdk/tools/RuntimeFrameworkReference.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.Platforms"
Version="$(MicrosoftNETCorePlatformsVersion)"
Condition="'$(MSBuildProjectExtension)'!='.vcxproj'"/>

<AdditionalPackageReference Include="Microsoft.NETCore.Platforms"
Version="$(MicrosoftNETCorePlatformsVersion)"
Condition="'$(ManagedCxx)'=='true'"/>
Condition="'$(MSBuildProjectExtension)'!='.vcxproj' or '$(ManagedCxx)'=='true'"/>

<!--
Workaround - this should be removed when our tests are converted from Microsoft.NET.Sdk.WindowsDesktop => Microsoft.NET.Sdk
Expand Down Expand Up @@ -42,63 +38,4 @@
Condition="'$(UseOOBNETCoreAppAppHostPack)' == 'true'" />
</ItemGroup>

<!-- These properties can be removed when vcxproj's NuGet support gets enabled. -->
<PropertyGroup>
<EnableTargetingPackDownload Condition="'$(UseOOBNETCoreAppTargetingPack)' == 'true' and '$(MSBuildProjectExtension)' == '.vcxproj'">false</EnableTargetingPackDownload>
<EnableRuntimePackDownload Condition="'$(UseOOBNETCoreAppRuntimePack)' == 'true' and '$(MSBuildProjectExtension)' == '.vcxproj'">false</EnableRuntimePackDownload>
<GenerateErrorForMissingTargetingPacks Condition="'$(EnableTargetingPackDownload)' == 'false'">false</GenerateErrorForMissingTargetingPacks>

<EnableAppHostPackDownload Condition="'$(UseOOBNETCoreAppAppHostPack)' == 'true' and '$(MSBuildProjectExtension)' == '.vcxproj'">false</EnableAppHostPackDownload>
</PropertyGroup>

<!-- Update paths for resolved packs which is necessary when the packs couldn't be resolved.
This happens when package download is disabled and the package isn't available in the SDK's packs folder.
This entire target can be removed when vcxproj's NuGet support gets enabled. -->
<Target Name="UpdateOOBPacks"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'"
AfterTargets="ResolveFrameworkReferences">
<ItemGroup>
<Error Text="'MicrosoftNETCoreAppRefVersion' is not set. Please set it to the version of the targeting pack you want to use." Condition="'$(UseOOBNETCoreAppTargetingPack)' == 'true' and '$(MicrosoftNETCoreAppRefVersion)' == ''" />
<Error Text="'MicrosoftNETCoreAppRuntimewinx64Version' is not set. Please set it to the version of the runtime pack you want to use." Condition="('$(UseOOBNETCoreAppRuntimePack)' == 'true' or '$(UseOOBNETCoreAppAppHostPack)' == 'true') and '$(MicrosoftNETCoreAppRuntimewinx64Version)' == ''" />

<ResolvedTargetingPack Path="$(NuGetPackageRoot)microsoft.netcore.app.ref\$(MicrosoftNETCoreAppRefVersion)"
NuGetPackageVersion="$(MicrosoftNETCoreAppRefVersion)"
PackageDirectory="$(NuGetPackageRoot)microsoft.netcore.app.ref\$(MicrosoftNETCoreAppRefVersion)"
Condition="'$(UseOOBNETCoreAppTargetingPack)' == 'true' and '$(EnableTargetingPackDownload)' == 'false' and '%(ResolvedTargetingPack.RuntimeFrameworkName)' == 'Microsoft.NETCore.App'" />

<ResolvedRuntimePack PackageDirectory="$(NuGetPackageRoot)microsoft.netcore.app.runtime.%(RuntimeIdentifier)\$(MicrosoftNETCoreAppRuntimewinx64Version)"
NuGetPackageVersion="$(MicrosoftNETCoreAppRuntimewinx64Version)"
Condition="'$(UseOOBNETCoreAppRuntimePack)' == 'true' and '$(EnableRuntimePackDownload)' == 'false' and '%(ResolvedRuntimePack.FrameworkName)' == 'Microsoft.NETCore.App'" />
</ItemGroup>

<PropertyGroup>
<_ResolvedRuntimePackPath>@(ResolvedRuntimePack->WithMetadataValue('FrameworkName', 'Microsoft.NETCore.App')->Metadata('Path'))</_ResolvedRuntimePackPath>
</PropertyGroup>

<ItemGroup>
<ResolvedFrameworkReference Condition="'%(Identity)' == 'Microsoft.NETCore.App'">
<TargetingPackPath Condition="'$(UseOOBNETCoreAppTargetingPack)' == 'true' and '$(EnableTargetingPackDownload)' == 'false'">$(NuGetPackageRoot)microsoft.netcore.app.ref\$(MicrosoftNETCoreAppRefVersion)</TargetingPackPath>
<TargetingPackVersion Condition="'$(UseOOBNETCoreAppTargetingPack)' == 'true' and '$(EnableTargetingPackDownload)' == 'false'">$(MicrosoftNETCoreAppRefVersion)</TargetingPackVersion>
<RuntimePackPath Condition="'$(UseOOBNETCoreAppRuntimePack)' == 'true' and '$(EnableRuntimePackDownload)' == 'false'">$(_ResolvedRuntimePackPath)</RuntimePackPath>
<RuntimePackVersion Condition="'$(UseOOBNETCoreAppRuntimePack)' == 'true' and '$(EnableRuntimePackDownload)' == 'false'">$(MicrosoftNETCoreAppRuntimewinx64Version)</RuntimePackVersion>
</ResolvedFrameworkReference>

<ResolvedAppHostPack Path="$(NuGetPackageRoot)microsoft.netcore.app.host.%(RuntimeIdentifier)\$(MicrosoftNETCoreAppRuntimewinx64Version)\%(ResolvedAppHostPack.PathInPackage)"
PackageDirectory="$(NuGetPackageRoot)microsoft.netcore.app.host.%(RuntimeIdentifier)\$(MicrosoftNETCoreAppRuntimewinx64Version)"
Condition="'$(UseOOBNETCoreAppAppHostPack)' == 'true' and '$(EnableAppHostPackDownload)' == 'false'" />

<ResolvedIjwHostPack Path="$(NuGetPackageRoot)microsoft.netcore.app.host.%(RuntimeIdentifier)\$(MicrosoftNETCoreAppRuntimewinx64Version)\%(ResolvedIjwHostPack.PathInPackage)"
PackageDirectory="$(NuGetPackageRoot)microsoft.netcore.app.host.%(RuntimeIdentifier)\$(MicrosoftNETCoreAppRuntimewinx64Version)"
Condition="'$(UseOOBNETCoreAppAppHostPack)' == 'true' and '$(EnableAppHostPackDownload)' == 'false'" />
</ItemGroup>

<PropertyGroup Condition="'@(ResolvedAppHostPack)' != '' And '$(AppHostSourcePath)' == ''">
<AppHostSourcePath>@(ResolvedAppHostPack->'%(Path)')</AppHostSourcePath>
</PropertyGroup>

<PropertyGroup Condition="'@(ResolvedIjwHostPack)' != '' And '$(IjwHostSourcePath)' == ''">
<IjwHostSourcePath>@(ResolvedIjwHostPack->'%(Path)')</IjwHostSourcePath>
</PropertyGroup>
</Target>

</Project>
154 changes: 0 additions & 154 deletions eng/WpfArcadeSdk/tools/Wpf.Cpp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -276,160 +276,6 @@ using namespace System::Runtime::Versioning;
</ItemGroup>
</Target>


<PropertyGroup Condition="'$(ManagedCxx)'=='true'">
<ResolveReferencesDependsOn>
CppCliHelper;
$(ResolveReferencesDependsOn)
</ResolveReferencesDependsOn>
<EnsureWpfProjectReferenceDependsOn>
$(EnsureWpfProjectReferenceDependsOn);
CppCliHelper
</EnsureWpfProjectReferenceDependsOn>
</PropertyGroup>

<!--
Helper for building C++/CLI projects
C++/CLI doe not have Sdk support for build on .NET Core
We use existing support for C# to discover Nuget packages, and pass it along to
the C++ compiler.
A simple C# project is generated dynamically. It contains PackageReferences for common packages
that are used in WPF's C++/CLI projects. There are only two such projects - DirectWriteForwarder
and System.Printing - which makes it unnecessary to create a flexible and parametrized target. This
can remain a simple and one-size-fits-all target for now.
If additional Nuget references need to be discovered and passed along for builds (for existing, or new) of
C++/CLI projects, they just need to be added to the vcxproj project file like this:
<AdditionalPackageReference Include="Microsoft.Win32.Registry" Version="<version>" />
-->
<Target Name="CppCliHelper"
Returns="@(Reference)"
Condition="'$(ManagedCxx)' == 'true'">

<PropertyGroup>
<CppCliHelperProject>$(IntermediateOutputPath)CppCliSupport\CppClrSupport_$(MSBuildProjectName).csproj</CppCliHelperProject>
</PropertyGroup>

<ItemGroup>
<CppClrSupportProject Include="ProjectHeader">
<!--
In the CDATA section that follows,
%40 ~= @
%25 ~= %
%3B ~= ;
%24 ~= $
-->
<Text>
<![CDATA[
<Project Sdk="Microsoft.NET.Sdk" InitialTargets="EnumerateAdditionalNugetReference">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Platforms>AnyCPU%3Bx64%3Barm64</Platforms>
</PropertyGroup>
]]>
</Text>
</CppClrSupportProject>


<CppClrSupportProject Include="ProjectBody">
<Text>
<![CDATA[
<Target Name="EnumerateAdditionalNugetReference"
BeforeTargets="_GenerateRestoreGraph"
Condition="'%24(AdditionalPackages)'!=''"
Returns="%40(PackageReference)">
<ItemGroup>
<_AdditionalPackages Remove="%40(_AdditionalPackages)" />
<_AdditionalPackages Include="%24(AdditionalPackages)" />
<PackageReference Include="%24([System.String]::Copy('%25(_AdditionalPackages.Identity)').Split('+')[0])"
Version="%24([System.String]::Copy('%25(_AdditionalPackages.Identity)').Split('+')[1])" />
<AdditionalNugetIds Remove="%40(AdditionalNugetIds)" />
<AdditionalNugetIds Include="%24([System.String]::Copy('%25(_AdditionalPackages.Identity)').Split('+')[0])" />
</ItemGroup>
<!--
Removing the Microsoft.NETCore.Platforms directly and then
adding it again to remove the duplicate reference.
-->
<ItemGroup>
<PackageReference Remove="Microsoft.NETCore.Platforms" />
<PackageReference Include="Microsoft.NETCore.Platforms"
Version="$(MicrosoftNETCorePlatformsVersion)" />
</ItemGroup>
</Target>
<Target
Name="IdentifyNugetReferences"
AfterTargets="ResolveAssemblyReferences"
Returns="%40(NugetReferencesForCppCli)">
<!-- Save Microsoft.NETCore.App assemblies and return them -->
<ItemGroup>
<NugetReferencesForCppCli Remove="%40(NugetReferencesForCppCli)" />
</ItemGroup>
<FilterItem1ByItem2 Item1="%40(ReferencePath->'%25(NuGetPackageId)')"
PreserveItem1Metadata="true"
Item2="%40(AdditionalNugetIds)"
Metadata2="Identity">
<Output ItemName="_NugetReferencesForCppCli" TaskParameter="Result" />
</FilterItem1ByItem2>
</Target>
<ItemGroup>
<NugetReferencesForCppCli Include="%40(_NugetReferencesForCppCli->'%25(OriginalItemSpec)')" />
</ItemGroup>
</Project>
]]>
</Text>
</CppClrSupportProject>
</ItemGroup>

<MakeDir Condition="!Exists('$(IntermediateOutputPath)CppCliSupport\')"
Directories="$(IntermediateOutputPath)CppCliSupport\" />

<Delete Files="$(CppCliHelperProject)" Condition="Exists('$(CppCliHelperProject)')" />

<WriteLinesToFile Lines="%(CppClrSupportProject.Text)"
File="$(CppCliHelperProject)"
Overwrite="false" WriteOnlyWhenDifferent="false" />

<!--
Do not build - just ask ResolveReferences + IdentifyNetCoreReferences for the information
we are looking for, namely the list of .NET Core Sdk references.
-->
<ItemGroup>
<ProjectToBuild Remove="@(ProjectToBuild)" />
<ProjectToBuild Include="$(CppCliHelperProject)">
<AdditionalProperties>AdditionalPackages=@(AdditionalPackageReference->'%(Identity)+%(Version)')</AdditionalProperties>
</ProjectToBuild>
</ItemGroup>
<MSBuild Projects="@(ProjectToBuild)"
Targets="Restore;ResolveReferences;IdentifyNugetReferences"
Properties="TargetFramework=$(TargetFramework);Platform=$(Architecture);RuntimeIdentifier=win-$(Architecture)">
<Output TaskParameter="TargetOutputs" ItemName="NugetReferencesForCppCli" />
</MSBuild>

<!--
Add the newly discovered list of .NET core references to $(AdditionalExplicitAssemblyReferences)
-->
<ItemGroup Condition="'$(CopyTransitiveReferences)'=='false'">
<Reference Include="@(NugetReferencesForCppCli)">
<Private>False</Private>
</Reference>
</ItemGroup>

<ItemGroup Condition="'$(CopyTransitiveReferences)'!='false'">
<Reference Include="@(NugetReferencesForCppCli)" />
</ItemGroup>
</Target>


<PropertyGroup Condition="'$(ManagedCxx)'!='true'">
<ResolveReferencesDependsOn>
CppHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
</ItemGroup>
<PropertyGroup>
<UseDestinationLibFolder>true</UseDestinationLibFolder>
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
<RestoreProjectStyle>Unknown</RestoreProjectStyle>
<!--
Opting out of this to ensure _WindowsBaseReference is used as
OutputItemsType in the project reference later.
Expand Down Expand Up @@ -86,11 +84,8 @@
<CLCompile Include="main.cpp" />
<CLCompile Include="OtherAssemblyAttrs.cpp" />
</ItemGroup>
<!--
PackageReferences to pass to CppCliHelper target
-->
<ItemGroup>
<AdditionalPackageReference Include="$(SystemIOPackagingPackage)" Version="$(SystemIOPackagingVersion)" />
<PackageReference Include="$(SystemIOPackagingPackage)" Version="$(SystemIOPackagingVersion)" />
</ItemGroup>
<!--
Ignore ijwhost.dll during packaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
</ItemGroup>
<PropertyGroup>
<UseDestinationLibFolder>true</UseDestinationLibFolder>
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<RestoreProjectStyle>Unknown</RestoreProjectStyle>
<!--
Opting out of this to ensure _defineReference is used as
OutputItemsType in the project references later.
Expand Down Expand Up @@ -155,11 +152,8 @@
<Define>REACHFRAMEWORK_DLL</Define>
</ProjectReference>
</ItemGroup>
<!--
PackageReferences to pass to CppCliHelper target
-->
<ItemGroup>
<AdditionalPackageReference Include="$(SystemIOPackagingPackage)" Version="$(SystemIOPackagingVersion)" />
<PackageReference Include="$(SystemIOPackagingPackage)" Version="$(SystemIOPackagingVersion)" />
</ItemGroup>
<!--
Ignore ijwhost.dll during packaging
Expand Down

0 comments on commit 601f3c5

Please sign in to comment.