4

Edit #1 Start

To Replicate this:

  1. Create a new "vanilla" WPF application addressing .Net Core 3.1
  2. Add an Windows Application Packaging Project to the solution (follow the steps mentioned in Set up your desktop application for MSIX packaging in Visual Studio)
  3. Try to "deploy" to a UNC path...

Edit #1 End


I am in the process of converting a WPF .net framework application to .net core 3.1. This application is an "internal" tool that we've always deployed by using ClickOnce to place create the setup on a shared UNC path. So simple....

I've now re-written it in .Net Core and need to deploy it. Finding that "ClickOnce" is no longer available, I understand that I have to go down the "MSIX" route. The documentation looks like it should be simple, but I guess I'm missing a few things....

1 - I've had to change my Developer Settings from "Side Bar" to "Developer Mode" 2 - It builds fine on my machine, but on Azure DevOps fails 3 - and how do I actually deploy it...?

Let's look at each in turn.

1 - Side Bar => Developer Mode issue

I add a new Windows Application Packaging Project to my solution, pick Windows version 1909 for both target and minimum versions, and set my WPF application to be the Entry Point. I try to run this and it forces me to change from "Side Bar" to "Developer Mode".

Is this only affecting me as the developer....if so, that's fine. I doubt the final end users will want to do this.

2 - Azure DevOps build pipeline fails

Locally, it compiles just fine, even under Release Mode where I have all warnings set to Error, and have FxCop running. Push it to Azure and it says:

[error]C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5): Error NETSDK1047: Assets file 'd:\a\1\s\MyApp\MyApp\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.1/win-x86'.
Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project.
You may also need to include 'win-x86' in your project's RuntimeIdentifiers.

Okay

  • my YAML file has a "Restore NuGet Packages" step preceding the build that succeeded.
  • I look in my SKD project file for my application and I see <TargetFramework>netcoreapp3.1</TargetFramework>
  • Regarding "RuntimeIdentifiers", I found the link Additions to the csproj format for .NET Core so added <RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers> immediately under <TargetFramework>netcoreapp3.1</TargetFramework> (should I be more specific an use win10-x64;win10-x86?)

Either way, this failed with a slightly different message:

There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "path to my dll", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

3 - how do I actually deploy it?

From MSIX: The Modern Way to Deploy Desktop Apps on Windows it states:

To generate the actual MSIX package, there’s a wizard available under Project | Store | Create App Packages in Visual Studio.

There isn't on my machine....I even went as far as installing the Visual Studio workload "Universal Windows Platform Development". I can see a "Deploy" under the Build menu...but is this it....where do I put the UNC path?

I think I'm missing something fairly fundamental....

The relevant part of my CSPROJ is

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

The package project is:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
    <VisualStudioVersion>15.0</VisualStudioVersion>
  </PropertyGroup>
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x86">
      <Configuration>Debug</Configuration>
      <Platform>x86</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x86">
      <Configuration>Release</Configuration>
      <Platform>x86</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|ARM">
      <Configuration>Debug</Configuration>
      <Platform>ARM</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|ARM">
      <Configuration>Release</Configuration>
      <Platform>ARM</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|ARM64">
      <Configuration>Debug</Configuration>
      <Platform>ARM64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|ARM64">
      <Configuration>Release</Configuration>
      <Platform>ARM64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|AnyCPU">
      <Configuration>Debug</Configuration>
      <Platform>AnyCPU</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|AnyCPU">
      <Configuration>Release</Configuration>
      <Platform>AnyCPU</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup>
    <WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
  </PropertyGroup>
  <Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
  <PropertyGroup>
    <ProjectGuid>08b169a2-6461-440b-afa1-ca35c7d98aa7</ProjectGuid>
    <TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
    <TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
    <DefaultLanguage>en-US</DefaultLanguage>
    <AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
    <EntryPointProjectUniqueName>..\MyApp\MyApp.csproj</EntryPointProjectUniqueName>
    <PackageCertificateThumbprint>01C08F1E21D5624A484DB362BE4F056504B825CC</PackageCertificateThumbprint>
  </PropertyGroup>
  <ItemGroup>
    <AppxManifest Include="Package.appxmanifest">
      <SubType>Designer</SubType>
    </AppxManifest>
  </ItemGroup>
  <ItemGroup>
    <Content Include="Images\SplashScreen.scale-200.png" />
    <Content Include="Images\LockScreenLogo.scale-200.png" />
    <Content Include="Images\Square150x150Logo.scale-200.png" />
    <Content Include="Images\Square44x44Logo.scale-200.png" />
    <Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
    <Content Include="Images\StoreLogo.png" />
    <Content Include="Images\Wide310x150Logo.scale-200.png" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\MyApp\MyApp.csproj">
      <SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>

(can/should I remove references to the "DEBUG" and to "ARM" which I don't think will be relevant??)

And the manifest is

<?xml version="1.0" encoding="utf-8"?>

<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  IgnorableNamespaces="uap rescap">

  <Identity
    Name="46aebba6-d403-4412-89c0-05279b36e54e"
    Publisher="CN=MyCompany"
    Version="2020.5.0.0" />

  <Properties>
    <DisplayName>MyApp</DisplayName>
    <PublisherDisplayName>MyCompany</PublisherDisplayName>
    <Logo>Images\StoreLogo.png</Logo>
  </Properties>

  <Dependencies>
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
  </Dependencies>

  <Resources>
    <Resource Language="x-generate"/>
  </Resources>

  <Applications>
    <Application Id="App"
      Executable="$targetnametoken$.exe"
      EntryPoint="$targetentrypoint$">
      <uap:VisualElements
        DisplayName="MyApp.Package"
        Description="MyApp.Package"
        BackgroundColor="transparent"
        Square150x150Logo="Images\Square150x150Logo.png"
        Square44x44Logo="Images\Square44x44Logo.png">
        <uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
        <uap:SplashScreen Image="Images\SplashScreen.png" />
      </uap:VisualElements>
    </Application>
  </Applications>

  <Capabilities>
    <Capability Name="internetClient" />
    <rescap:Capability Name="runFullTrust" />
  </Capabilities>
</Package>

Thanks!

jps
  • 20,041
  • 15
  • 75
  • 79
DrGriff
  • 4,394
  • 9
  • 43
  • 92
  • 1
    In Visual Studio 2019, there should be a Publish | Create app packages option available if you right-click on the Windows Application Packaging Project. – mm8 May 18 '20 at 13:25
  • @mm8 - ah thank you...how did I fail to spot that? Guess I wasn't looking for it under "Publish". I do though still get the error (see in next comment) that seems clear enough....I'm just not exactly sure how to fix: – DrGriff May 18 '20 at 13:54
  • Error: `There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\MyApp\MyApp\bin\x86\Release\netcoreapp3.1\win-x86\MyApp.dll", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project` – DrGriff May 18 '20 at 13:55
  • In the Configuration Manager I see two entries: `Project=MyApp,Configuration=Release,Platform=Any CPU,Build=checkedDeploy=unchecked` and `Project=MyApp.Package,Configuration=Release,Platform=Any CPU,Build=checkedDeploy=unchecked`. They're the same...why the above error message? – DrGriff May 18 '20 at 14:32
  • If you look in the article, everything targets x86 only. – mm8 May 18 '20 at 14:33
  • @mm8 Yes, I saw that. The end user really needs to run the application as 64 bit because it loads huge text files into memory. Guess "targets x86" doesn't refer to the end installation but the creation of the installation package?? The article says "If you receive errors, open Configuration Manager and ensure that your projects target the same platform". Their screen shot shows everything as "debug" (surely you'd want "release"?) and whilst I can pick x86 for the Packaging project, I only have "Any CPU" for my WPF app (only other options are "" or ""). – DrGriff May 18 '20 at 16:12
  • @mm8 - I went to the WPF's project page and changed that to be x64, and then in the Configuration Manager set the Packaging project to also be x64. When Publishing I only selected the X64 and Arm 64 options. I then got "Assets file '....\obj\wappublish\win-x64\project.assets.json' not found. Run a NuGet package restore to generate this file." NuGet restore did NOT fix this. It's easy to replicate by creating a brand new vanilla WPF project targeting Core 3.1 (if you've time :-)). – DrGriff May 18 '20 at 16:25
  • "I then got "Assets file '....\obj\wappublish\win-x64\project.assets.json' not found. Run a NuGet package restore to generate this file." NuGet restore did NOT fix this." Did you find a solution to this? – tech74 Sep 29 '20 at 17:26
  • BTW. This MSIX approach caused us so many problems - 1) it's a relatively lengthy process to publish, 2) on some Dev's machines it worked, on other's it didn't, and 3) when we pushed an update, some user's machines automatically updated whilst others didn't. All very confusing and time consuming. Then Microsoft re-introduced `ClickOnce` and we immediately ditched the MSIX approach for this and haven't looked back since. It's quick, and it works, and the developers all are smiling again. – DrGriff May 21 '21 at 10:48

1 Answers1

1

In .wapproj project file please add,

<PropertyGroup>
    <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
        None
    </ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>