DLL + .NET Standard + Click Once

Unable to initialize the application (Could not load file or assembly ‘System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The System cannot find the file specified.

Unable to install or run the application.  The application requires that the assembly System.Drawing.Primitives Version 4.02.0 be installed in the Global Assembly Cache (GAC) first.  Please contact your system administrator

The following guide will resolve the current Click Once deployment bug in Visual Studio Community to Visual Studio Enterprise (Versions 15.6.7 and lower).

Note this fix is specifically for Application Executables in .NET Framework (4.6.1).

TECHNOLOGY

.NET Standard

Framework

CATEGORIES

Click Once Deployment

CODE

C# | C Sharp

GitHub Source

Replicating the Issue:

Replication was tested on 7/21/2018

Resolving the Issue:

Microsoft is already aware of this issue and has a scheduled fix to be implemented in Visual Studio Versions 15.7 +

The Easy Way:

An application was created which does the brunt of the work for you. It modifies the manifest file, changing the assemblies from preRequisite to install. It moves the deployed DLLs to the publish folder. It then launches MageUI to resign the solution manifest and the application manifest.

You can find the source here.

Download the App.

It contains a complied .NET Standard Manifest as well as the required DLLs for the publish directory.  You can place this executable in any location.

You can download it here.

Publish Directory

  • Either copy the path or browse to the publish directory
  • …\Application Files\Application Name_1_0_0_0\

Solution Manifest File

  • Either copy the path or browse to the Solution Manifest File
  • …\Application Files\Application Name_1_0_0_0\App.Manifest
The Process
  • Modifies the Manifest File
    • Creates a backup (App.Manifest-original)
  • Copies the required DLLs to the publish location
    • …\Application Name_1_0_0_0\
  • Opens MageUI (.NET 3.5 / .NET 4.5 is required)
Mage UI w/ Solution Manifest
  • Open the Solution Manifest File
    • …\Application Name_1_0_0_0\App.Manifest
  • Click on the Tab Files > Check to make sure all files exist
    • A yellow triangle will display on the row if it’s missing
  • Save the solution manifest file (CTRL+S) with your certificate
Mage UI w/ Application Manifest
  • Open the Application Manifest File
    • …\Publish\App.Application | …\Publish\App.Vsto
  • Click on Tab Application References > Select Manifest…
    • Browse to the solution manifest file
  • Save the application manifest file (CTRL+S) with your certificate
Final Notes

Run Setup.exe on your current workstation.  If everything succeeded it should have installed successfully through Click Once.

If an error occurred while opening the manifest files through MageUI, the application failed.  Check the manifest file for duplicate entries, as well if it’s structured correctly in XML.

If it failed on the installation, either the signing process failed, or your missing a deployed DLL(s).

The Hard Way:

Create the solution from this article.

Correcting the Manifest File
  • Open the solution manifest file from the application exe
    • …\Publish\Application Files\Application Name_1_0_0_0\App.Exe.Manifest
  • Open the solution manifest file from the class library
    • …\Publish\Application Files\Application Name_1_0_0_0\App.Dll.Manifest

Do a quick compare of both files, you’ll notice that the DLL manifest compared to the EXE manifest has the same dependencies but one is set as preRequisite vs install. If you plan to do this manually compare each dependency and copy and paste any install from the EXE manifest and overwrite the same lines in the DLL manifest that are preRequisite.

Automated Approach (GitHub)

You can view the GitHub Source here.

In Manifest Routines, you’ll have three methods.   GetDependenciesIdentifiers is responsible for grabbing of all dependencies from the manifest. StandardDependencies is responsible for getting the standard net dependencies. UpdateManifestDependenciesis responsible for updating the DLL manifest from the EXE manifest.

Copy to Clipboard
Copying .NET Standard DLLs.deployed
  • Copy the .NET Standard Dlls from
    • …\Application\Publish to …\ClassLibrary\Publish
  • All DLLs will need to have the *.deploy appended
Copy to Clipboard
Resigning the Manifest Files with MageUI
  • Browse to C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\
    • Your path might be different but it should exist in NETFX *.*.* Tools\
  • Open file MageUi.exe
Mage UI w/ Solution Manifest
  • Open the Solution Manifest File
    • …\Application Name_1_0_0_0\App.Manifest
  • Click on the Tab Files > Check to make sure all files exist
    • A yellow triangle will display on the row if it’s missing
  • Save the solution manifest file (CTRL+S) with your certificate
Mage UI w/ Application Manifest
  • Open the Application Manifest File
    • …\Publish\App.Application | …\Publish\App.Vsto
  • Click on Tab Application References > Select Manifest…
    • Browse to the solution manifest file
  • Save the application manifest file (CTRL+S) with your certificate

Resources:

https://stackoverflow.com/questions/45843533/clickonce-deployment-does-not-install-as-expected

https://github.com/dotnet/standard/issues/529