mardi 20 août 2019

UWP ARM build to release : error APPX0002: Task 'GenerateAppxManifest' failed. An item with the same key has already been added.

Today I was about to release a new version of an application when I go this error.  This new build was mainly a classic sprint incrimination where I migrated my UWP libraries to .netstandard 2.0 and reworked and renamed small parts of the app to improve architecture of the app. No new features no major refactoring...


My day started with Azure DevOPs (VSTS) telling me:

- AppTest.ABC is not compatible with uap10.0.17134 (UAP,Version=v10.0.17134). Project AppTest.ABC supports: netstandard2.0 (.NETStandard,Version=v2.0)

I had a heart attack! netstandard2.0  doesn't support uap10.0.17134 since when ?!?

Looking at https://docs.microsoft.com/en-us/dotnet/standard/net-standard we can clearly see that the support starts at 10.0.16299 so this cant be the issue.

Next:

Having a deeper look at the logs in Visual Studio in Output window I saw that the nuget restore was telling me that I had

Incompatible projects: 3

Which is where I started my morning hunt to find the 3 rogue projects.

  •  To find these projects I looked at the logs and checked to see which libraries has issue
I was quickly able to find this one:
Checking compatibility for NotificationsExtensions.Win10 14332.0.2 with UAP,Version=v10.0.17134 (win10-arm) 
This was an old nuget package that I was not using anymore (don't ask me why it was not removed before), and having a second look I also saw that I had a NotificationsExtensions nuget package by removing these 2 packages I only had one incompatible projects left to find.

Nuget

Not being to find the last incompatible project I decided to look into my nuget packages to see what I could do. Here is the documentation https://docs.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders

Next I decided to clear all of my nuget packages:

You can clear all caches with this command:
nuget locals all -clear

This did not fix my issue, however when building the app in Debug ARM I was getting a new error: error APPX1101: Payload contains two or more files with the same destination path 'System.Memory.dll'.

 Full error:


6>"C:\AppTest\uap\src\AppTest.csproj" (_GenerateAppxPackage target) (1) ->
6>(_ComputeAppxPackagePayload target) -> 
6>  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\AppxPackage\Microsoft.AppXPackage.Targets(1793,5): error APPX1101: Payload contains two or more files with the same destination path 'System.Memory.dll'. Source files: 
6>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\AppxPackage\Microsoft.AppXPackage.Targets(1793,5): error APPX1101: C:\Users\damie\.nuget\packages\runtime.win10-arm-aot.microsoft.netcore.universalwindowsplatform\6.2.8\runtimes\win10-arm-aot\lib\uap10.0.15138\System.Memory.dll
6>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\AppxPackage\Microsoft.AppXPackage.Targets(1793,5): error APPX1101: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PublicAssemblies\System.Memory.dll
6>

Something is going terribly wrong, I am building my app in 10.0.17134 and it is pulling a 10.0.15138 package version WHY??

runtime.win10-arm-aot.microsoft.netcore.universalwindowsplatform\6.2.8\runtimes\win10-arm-aot\lib\uap10.0.15138\System.Memory.dll

Looking a Visual Studio

I decide to check the Compile with .NET Native tool chain for the ARM builds to see if this would fix my error. The Compile with .NET chain was already active for my builds in x86 but not for ARM

Under My Project => Properties=>Build I checked :


Using the .NET Native tool chain allowed me to fix my issue as the application was now using these bits to build the app.

Now that I have my ARM builds working in Debug but still not in Release, to make things simpler I just opened my .csproj file and edited it as follows:


<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <OutputPath>bin\x86\Release\</OutputPath>
    <DefineConstants>$(DefineConstants);TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <Optimize>true</Optimize>
    <NoWarn>;2008</NoWarn>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
    <CodeAnalysisRuleSet />
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\ARM\Debug\</OutputPath>
    <DefineConstants>$(DefineConstants);DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <NoWarn>;2008</NoWarn>
    <DebugType>full</DebugType>
    <PlatformTarget>ARM</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
    <CodeAnalysisRuleSet />
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
    <OutputPath>bin\ARM\Release\</OutputPath>
    <DefineConstants>$(DefineConstants);TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <Optimize>true</Optimize>
    <NoWarn>;2008</NoWarn>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>ARM</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
    <CodeAnalysisRuleSet />
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x64\Debug\</OutputPath>
    <DefineConstants>$(DefineConstants);DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <NoWarn>;2008</NoWarn>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
    <CodeAnalysisRuleSet />
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <OutputPath>bin\x64\Release\</OutputPath>
    <DefineConstants>$(DefineConstants);TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <Optimize>true</Optimize>
    <NoWarn>;2008</NoWarn>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
    <CodeAnalysisRuleSet />
    <EnableGatekeeperAnalysis>true</EnableGatekeeperAnalysis>
  </PropertyGroup> 

In the end all I really needed to do was to enable
 <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
on my ARM builds which means to not have been the case before.

In the end I was able to once again build and release my application, I hope that this has helped you.