WindowsAppSDK: AnyCPU Class libraries are broken again

Describe the bug

Internal bug https://microsoft.visualstudio.com/OS/_workitems/edit/36498869

When building an AnyCPU class library, the build is broken again. Since it’s not an application, the architecture runtime limitation shouldn’t be in effect. The issue appears to be due to an incorrect condition in microsoft.windowsappsdk.foundation\1.0.0-experimental1\build\Microsoft.WindowsAppSDK.Bootstrap.targets:

  <Target Name="BinPlaceBootstrapDll" Condition="'$(AppxPackage)' != 'true'" AfterTargets="Build">
    <Copy SourceFiles="$(MSBuildThisFileDirectory)..\runtimes\lib\native\$(_WindowsAppSDKFoundationPlatform)\Microsoft.WindowsAppSDK.Bootstrap.dll" DestinationFolder="$(OutDir)" OverwriteReadOnlyFiles="true" ContinueOnError="false"/>
  </Target>

A class library isn’t an AppxPackage, but it isn’t a running application either.

Steps to reproduce the bug

Compile a class lib using reunion:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0-windows10.0.18362.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <Configurations>Debug;Release</Configurations>
    <Platforms>AnyCPU</Platforms>
  </PropertyGroup>

  <ItemGroup>
     <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0-experimental1" />
  </ItemGroup>
  
</Project>

Observe the error:

1>C:\Users\mn.nuget\packages\microsoft.windowsappsdk.foundation\1.0.0-experimental1\build\Microsoft.WindowsAppSDK.Bootstrap.targets(11,5): error MSB3030: Could not copy the file “C:\Users\mn.nuget\packages\microsoft.windowsappsdk.foundation\1.0.0-experimental1\build..\runtimes\lib\native\AnyCPU\Microsoft.WindowsAppSDK.Bootstrap.dll” because it was not found.

I managed to fix it locally by editing the above condition in the nuget package to this: Condition="'$(AppxPackage)' != 'true' AND !('$(_WindowsAppSDKFoundationPlatform)' == 'AnyCPU' AND '$(OutputType)'=='Library') "

Expected behavior Application compiles without error

Version Info

NuGet package version: 1.0.0-experimental1

Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 22 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve came up with a workaround. Not sure if it will work on all cases, but it is working for the WCT.

  <Target Name="FixReferenceCopyLocalPaths" BeforeTargets="ResolvePackageAssets">
    <ItemGroup>
      <ReferenceCopyLocalPaths Remove="$(PkgMicrosoft_WindowsAppSDK)\build\..\runtimes\lib\native\AnyCPU\Microsoft.WindowsAppRuntime.Bootstrap.dll"/>
    </ItemGroup>
  </Target>

You also need to add the GeneratePathProperty="true" to your PackageReference to the Microsoft.WindowsAppSDK nuget, like this:

<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0-preview3" GeneratePathProperty="true" />

Temporary workaround I found:

  <!-- Workaround for https://github.com/microsoft/WindowsAppSDK/issues/1217 -->
  <Target Name="FixBinPlaceBootstrapDll" BeforeTargets="BinPlaceBootstrapDll" >
    <PropertyGroup>
      <_WindowsAppSDKFoundationPlatform>x86</_WindowsAppSDKFoundationPlatform>
    </PropertyGroup>
  </Target>

Confirmed!

@DrusTheAxe should this be marked fixed given your fixes that went into preview2? Or are there still lingering issues here?

AnyCPU isn’t fixed yet. Here’s the set of events to address that https://github.com/microsoft/WindowsAppSDK/pull/1498#discussion_r719735938