Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Issues with .NET Standard and Click Once #529

Closed
terrajobst opened this issue Oct 6, 2017 · 64 comments
Closed

Issues with .NET Standard and Click Once #529

terrajobst opened this issue Oct 6, 2017 · 64 comments

Comments

@terrajobst
Copy link
Member

Summary

There is currently a bug that prevents ClickOnce setups from correctly deploying all the necessary .NET Standard support files. But you can work this around by editing your project file.

Symptoms and root cause

Running the application from inside of Visual Studio succeeds, so does publishing and installing. But when the application is launched, it crashes with with an exception like this one:

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.

The root cause is bug in the way ClickOnce discovers and packages dependencies from the application project.

Workaround

In order to make sure the right files are added to your installer, you need to add a custom target to your project file:

  1. Right click your project and select Unload Project.
  2. Then, right click your project again and select Edit <your project>.
  3. Locate the first <Import> element and copy & paste the code from below before the <Import> element.
  4. Right click your project and select Reload Project
  <ItemGroup>
    <PublishFile Include="netfx.force.conflicts">
      <Visible>False</Visible>
      <PublishState>Exclude</PublishState>
      <IncludeHash>True</IncludeHash>
      <FileType>Assembly</FileType>
    </PublishFile>
  </ItemGroup>
  <Target Name="FixClickOnceDependencies" BeforeTargets="_DeploymentComputeClickOnceManifestInfo">
    <ItemGroup>
      <_noCopyRefs Include="@(ReferencePath)" Condition="'%(ReferencePath.Private)' == 'false'" />
      <_noCopyRefsByFileName Include="@(_noCopyRefs->'%(FileName)')">
        <OriginalItem>%(Identity)</OriginalItem>
      </_noCopyRefsByFileName>
      <_libByFileName Include="@(ReferenceCopyLocalPaths->'%(FileName)')">
        <OriginalItem>%(Identity)</OriginalItem>
      </_libByFileName>
      <_overlappingRefByFileName Include="@(_noCopyRefsByFileName)" Condition="'@(_noCopyRefsByFileName)' == '@(_libByFileName)' AND '%(Identity)' != ''" />
      <_overlappingLibByFileName Include="@(_libByFileName)" Condition="'@(_noCopyRefsByFileName)' == '@(_libByFileName)' AND '%(Identity)' != ''" />
      <_overlappingRef Include="@(_overlappingRefByFileName->'%(OriginalItem)')" />
      <_overlappingLib Include="@(_overlappingLibByFileName->'%(OriginalItem)')" />
    </ItemGroup>
    <ItemGroup Condition="'@(_overlappingRef)' != ''">
      <ReferencePath Remove="@(_overlappingRef)" />
      <ReferencePath Include="@(_overlappingLib)">
        <Private>True</Private>
      </ReferencePath>
    </ItemGroup>
  </Target>
@JranZu
Copy link

JranZu commented Oct 24, 2017

Looking forward to this fix... Not so much implementing the workarounds ;) -- Any ETA? Soon, Summer 2018, etc?

@NArnott
Copy link

NArnott commented Oct 24, 2017

This doesn't appear to work. System.Runtime is still not getting deployed even after adding the extra target to my csproj.

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

JPhilC added a commit to JPhilC/DotNetSTDClickOnceIssues that referenced this issue Oct 25, 2017
…et/standard#529. The solution now publishes and installed but when run it just fails silently. The follow event logged in the Windows Application log.

Application: ClickOnceIssueDemo.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileNotFoundException Exception Info: System.IO.FileNotFoundException at ClickOnceIssueDemo.App..cctor() Exception Info: System.TypeInitializationException at ClickOnceIssueDemo.App.Main()
@JPhilC
Copy link

JPhilC commented Oct 25, 2017

This work around does not not work. It just moves the problem along so that the application will publish and install but it then will not run. You get an invisible APPCRASH with the following Application Event log.

Application: ClickOnceIssueDemo.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileNotFoundException Exception Info: System.IO.FileNotFoundException at ClickOnceIssueDemo.App..cctor() Exception Info: System.TypeInitializationException at ClickOnceIssueDemo.App.Main()

In the hope that someone can help with this I have created a simple application and put it here:.

I have been unable to determine what file is missing. The Fusion Log Viewer does not show anything and attaching the debugger directly to the exe does not give show any additional information either. I am at a loss how to resolve this. I have wasted a day and a half on this already.

The sample application targets .NET 4.7 and shows a main window displaying the time. It uses a .NET Standard 2.0 class library to provide the time. If you clone the repository and open the solution in VS2017 it will run fine.

The application is based on a sample provided by Laurent Bugnion of Galasoft for another issue I had related to his newly released .NET Standard version of MVVMLight.

[UPDATE]
I have just tried updating the test application to target .NET 4.7.1 and it seems to have resolved the issue. I removed the work-around hack to project file and it still seems to work. Going to try the same approach on the real project with which I am having problems.

[UPDATE 2]
Upgrading to target ,NET Framework 4.7.1 seems to have solved the issue for me. There are still minor niggles getting it to include certain files but at least now I see which files are missing in the Fusion Log Viewer.

@cilerler
Copy link

cilerler commented Nov 9, 2017

@terrajobst it seems it did not fix the issue

I compared the output between OnceClick and Non-OnceClick and files below are missing on OnceClick one. And because of that I'm getting the error Could not load file or assembly 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

Any workaround for that? Thanks in advance 🤗

System.Collections.Concurrent.dll
System.Collections.dll
System.ComponentModel.dll
System.ComponentModel.EventBasedAsync.dll
System.Diagnostics.Contracts.dll
System.Diagnostics.Debug.dll
System.Diagnostics.Tools.dll
System.Diagnostics.Tracing.dll
System.Dynamic.Runtime.dll
System.Globalization.dll
System.IO.Compression.dll
System.IO.dll
System.Linq.dll
System.Linq.Expressions.dll
System.Linq.Parallel.dll
System.Linq.Queryable.dll
System.Net.Http.dll
System.Net.Networklnformation.dll
System.Net.Primitives.dll
System.Net.Requests.dll
System.Net.WebHeaderCollection.dll
System.ObjectModel.dll
System.Reflection.dll
System.Reflection.Extensions.dll
System.Reflection.Primitives.dll
System.Resources.ResourceManager.dll
System.Runtime.dll
System.Runtime.Extensions.dll
System.Runtime.Handles.dll
System.Runtime.lnteropServices.dll
System.Runtime.Numencs.dll
System.Runtime.SerializationJson.dll
System.Runtime.Serialization.Primitives.dll
System.Runtime.Serialization.Xml.dll
System.Security.Principal.dll
System.Text.Encoding.dll
System.Text.Encoding.Extensions.dll
System.Text.RegularExpressions.dll
System.Threading.dll
System.Threading.Tasks.dll
System.Threading.Tasks.Parallel.dll
System.Threading.Timer.dll
System.Xml.ReaderWriter.dll
System.Xml.XDocument.dll
System.Xml.XmlSerializer.dll

Update Upgrading to target ,NET Framework 4.7.1 seems to have solved the issue for me too. I removed the work-around from the project file and it still seems working

@Shashanka77
Copy link

Actually we are still running into the issue with this ClickOnce deployment even after upgrading to 4.7.1.

@joperezr
Copy link
Member

Yes, this workaround won't work when targeting 4.7.1. We are in contact with the ClickOnce team in order to get a fix for this issue.

@clairernovotny
Copy link
Member

This also affects the Desktop Bridge WAP projects. The right files weren't getting copied into the AppX directory. Same list above.

@ikourfaln
Copy link

ikourfaln commented Nov 28, 2017

@terrajobst
regarding this issue, is there any update?!

@nzain
Copy link

nzain commented Feb 7, 2018

I've tested the described workaround on a net462 WPF clickonce project published from VS2017 - did not work. The app crashes and my log says

---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 
---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

when instantiating the first (main) viewmodel of the WPF application.

A few weeks ago we successfully published from VS2015 on net46 without any netstandard dependencies, of course. Unfortunately, we did not even see this issue during the upgrades, since it compiles and runs happily. Others have said, that upgrading to net471 might resolve the issue - gonna try now. However, I'm not sure if this is is acceptable, since there is no net471 installer for some windows 10 versions (we're behind company wsus).

@JPhilC
Copy link

JPhilC commented Feb 7, 2018

At the moment I think your only option is to publish to a staging area, edit the config file to change the version range of the affected assemblies then save as and resign the manifest files using mageui. That is the way I am currently deploying with clickonce. Here are my notes as to what I do:
image

@nzain
Copy link

nzain commented Feb 7, 2018

I can confirm that simply targeting net471 would resolve my issue, but that does not work on all company machines, since 471 only installs on some very specific win10 versions not available on our wsus. We give up (restored last working net46 clickonce version without netstandard dependencies) and wait.

@NArnott
Copy link

NArnott commented Feb 7, 2018

net471 doesn't appear to solve my issue, and I'm also concerned that net471 is limited on the windows versions. We are now very much in a stuck situation. We need to use nuget packages that have dependencies (such as Microsoft.Extensions.Logging), which only has a netstandard1.1 version. Once we pull those kind of nugets into a WPF app that uses clickonce, our deploys fail.

Is there any work happening to fix this?

@kevingoos
Copy link

I am looking into the same deploy issue, and like @nzain said, upgrading to 4.7.1 will limit the windows versions. Hope there will be a fix soon?

@joperezr
Copy link
Member

joperezr commented Feb 7, 2018

Yes, we are very sorry you are hitting these issues. We have identified the problem and have contacted the clickOnce team in order for them to fix this ASAP. The fix is on track to make it to VS 15.8.

@kevingoos
Copy link

@joperezr and is there any info about when this vs version will be released?

@Shashanka77
Copy link

Has anyone tried adding these dlls to the project as content ?

@kevingoos
Copy link

@Shashanka77 no not tried this yet, feel free to try!

@joperezr
Copy link
Member

joperezr commented Feb 8, 2018

is there any info about when this vs version will be released?

I believe timelines for releases are not defined yet, but I'll try to find out and update this thread.

@NArnott
Copy link

NArnott commented Feb 8, 2018

@Shashanka77 I just tried the dlls as content files, as it seems to work. It seems that in general Click Once blacklists any assembly that matches one that exists in the .NET Framework, such as System.Runtime or System.IO. Assembly names like System.IO.Compression doesn't exist in the framework, so makes it into clickonce deployments by default.

Adding as content files (which I have about 10 that were needed) adds more management, such as when adding or upgrading nuget packages, but it works for now. Really looking forward to that fix.

Here's an example of the addition to my csproj file that forces their inclusion into a clickonce package:

<Content Include="..\packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll"> <Link>System.Diagnostics.Tracing.dll</Link> </Content>

@vrykov
Copy link

vrykov commented Feb 19, 2018

@joperezr are there any news about this issue? This is real pain for me

@clairernovotny
Copy link
Member

clairernovotny commented Feb 19, 2018

@NArnott What if you use a glob? I had to do something similar, for similar reasons, for the WAP packaging project for Desktop Bridge apps. Adding the entire output directory of the app as content, with the right Link path, did the trick:

https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/blob/afe915819a7411113c5043f53cfb3355cd66bf24/PackageExplorer.Package/PackageExplorer.Package.wapproj#L56-L58

<Content Include="..\PackageExplorer\bin\$(Configuration)\net461\**\*.dll">
    <Link>NuGetPackageExplorer\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Content>

@NArnott
Copy link

NArnott commented Feb 19, 2018

@onovotny Thanks for the trick. I tried it, and started getting errors from clickonce that files were already installed. Looks like any assembly that is referenced both in the project as a dll, and as content (per your work-around), would end up in the click-once manifest twice, causing it to fail to download on a user machine. Any ideas how to solve that problem?

@saulyt
Copy link

saulyt commented May 11, 2018

I too am having this issue. I see that 15.8 is now released in preview. Has anyone installed it to verify that this issue is fixed?

@arthurvb
Copy link

arthurvb commented May 18, 2018

For our deployment it seems that installing the latest .net framework (4.7.2) on the client fixes the issue.

@saulyt
Copy link

saulyt commented May 18, 2018

@arthurvb Was it enough to install 4.7.2 on the deployment machine, or did you need to target 4.7.2 in your application?

@banksdev
Copy link

Upgrading to .NET 4.7.2 did not work for me sadly, however I have found that going into the Project Properties -> Publish, and clicking Application Files and then one by one setting the assemblies needed to Include instead of Prerequisite worked for me.

@arthurvb
Copy link

@saulyt only on the machine where the program is run

@saulyt
Copy link

saulyt commented Jun 6, 2018

I upgraded a machine to .NET 4.7.2 and did not have the missing file error during the clickonce installation, but the program crashed on startup with no error message (just disappeared and was no longer running.) I then installed VS 15.8 Preview and installed again on the 4.7.2 machine and it worked. However, when I tried installing it on a machine with 4.7.1 I once again received the missing files error during installation. It seems that VS 15.8 does not fix the issue (at least if you are not running .NET 4.7.2).

@JPhilC
Copy link

JPhilC commented Jun 7, 2018

Just been looking at the fixed issues in VS 15.8 Preview 2 and this issue does not appear to be there. Can someone confirm whether a fix for this issue is scheduled for release with VS 15.8?

@joperezr
Copy link
Member

As far as I can tell, unfortunately, ClickOnce team haven't yet been able to produce a fix for this issue. I'll push for somebody on their team to report back to this thread so that we can get an ETA and a state of things.

@kevingoos
Copy link

@joperezr any progress?

@joperezr
Copy link
Member

I was able to get in touch with the ClickOnce team and they say the fix is still targeting 15.8. It just hasn't been on the Previews of 15.8 yet, but it should be there for RTM.

@RhomGit
Copy link

RhomGit commented Jun 27, 2018

@joperezr Thanks for the update.

Its pretty disappointing this has taken so long to resolve (if indeed it even has been resolved).
https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-preview-relnotes#15.8_Preview3

@John-Hart
Copy link

John-Hart commented Jun 27, 2018

As @joperezr mentioned, it will be included in 15.8, unfortunately we did just miss the deadline for Preview 3.

@kevingoos
Copy link

kevingoos commented Jun 29, 2018

@John-Hart So if I understand it correctly, the fix is implemented at this point?
Sorry that we are so skeptical about this now, but we are already waiting for 6 months on a fix, which is crucial to start using .net standard, in a stable way, in our project...

@kevingoos
Copy link

I cannot find it in preview 4 either?

@jmatheti
Copy link

This was the issue with 15.5.6 target 4.7.1, after VS update to 15.7.5 today its got fixed with the work around specified on the top of this thread.

@cealmees
Copy link

@Janidbest Is really solved the issue? Today I started ClickOnce for a new production release which is scheduled for tomorrow. I guess we all lucky today!

@dj-curls
Copy link

Adding this to my csproj, after retargeting 4.7.1 doesn't work

<ItemGroup> <Content Include="..\PackageExplorer\bin\$(Configuration)\net461\**\*.dll"> <Link>NuGetPackageExplorer\%(RecursiveDir)%(Filename)%(Extension)</Link> </Content> </ItemGroup>

Also upgrading to .net 4.7.2 didn't work either. Really looking forward to this fix

@rholsman
Copy link

I was having this issue with a 4.7.1 WPF app, but went into the publish settings on the wpf projects properties and then under install mode and settings section clicked the application files button. Found the missing reference which for me was system.net.http.dll which had its publish status as Prerequisite and changed it to Include and this resolved the issue. I am running VS 15.7.5 and seem to be able to resolve the issue with this.

@clintmasden
Copy link

If you are publishing a WPF / WinForms Application you can go to your Project > Properties > Publish > Application Files > and change Publish Status ( Prerequisite (Auto) to Include). Original Source Stack Overflow Step by Step Process. If you are deploying a Class Library or VSTO addin that's where it becomes complex since you don't have "Publish > Application Files", in which you have to manually modify the Click Once Manifest to include the DLLs, Add the Deployed DLLs to the publish directory, and finally resign it the solution manifest and the application manifest with MageUI. I created an article that is also Step By Step here.

@RhomGit
Copy link

RhomGit commented Jul 28, 2018

As @joperezr mentioned, it will be included in 15.8, unfortunately we did just miss the deadline for Preview 3.

Has anyone tested if the fix is any of the latest couple of 15.8 previews?
Visual Studio 2017 version 15.8 Preview 5 - released July 26, 2018

edit: I saw on this thread that the fix should be available now on the previews (since mid-July).
https://developercommunity.visualstudio.com/content/problem/111414/clickonce-with-dependcy-with-netstandard-does-not.html

@willson556
Copy link

Has anyone tested if the fix is any of the latest couple of 15.8 previews?
Visual Studio 2017 version 15.8 Preview 5 - released July 26, 2018

I successfully built a ClickOnce release today with no project edits and a target of .NET Framework 4.7.1 using 15.8 Preview 5.

@RealDotNetDave
Copy link

I am able to create a ClickOnce package now without any issues in VS2017. I still don't see .NET Core as a prerequisite. Will that be added?

@velvetdust
Copy link

velvetdust commented Aug 8, 2018

We have this error (Unable to install or run the application. The application requires that assembly System.Xml.XPath.XDocument Version 4.1.0.0 be installed in the Global Assembly Cache (GAC) first.) only for users with Windows x86. Users with Windows x64 can install and use ClickOnce app without errors

@Daniel-Svensson
Copy link

Is this fix intended to solve dotnet/msbuild#3057 and dotnet/msbuild#3058 ?

@noisycarlos
Copy link

Honestly, I'm not quite sure what I copy/pasted into my project, but it worked. Thanks!

In my case, I got an error on Installation that said something like "The application requires that assembly netfx.force.conflicts version 0.0.0.0"

@joperezr
Copy link
Member

@RealDotNetDave

I still don't see .NET Core as a prerequisite. Will that be added?

.NET Core is not a prerequisite for your app to run. Your app will run on .NET Framework, and it only needs the right facades in place in order to work. With the fixes that the ClickOnce team made, these facades will be packaged as well, so it is not a requisite to have .NET Core.

@terrajobst
Copy link
Member Author

Closing as this an announcement. For the record, we've started to track issues related to .NET Framework support with this label.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests