1
votes

I have recently added MVC in my .NET Core 2.0 project which runs on .NET Framework 4.7 (<TargetFramework>net47</TargetFramework>). It is a Web-project which gets hosted locally via a Kestrel-server. Before I added MVC there were no issues.

I build it on my developer machine (Visual Studio 2017) and when I run it there, it works correctly. (because there exists the folder: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7 with all the required assemblies). These are added in the project as assemblies (automatically).

But when I copy the bin/release to a new Win10 machine (where .NET Framework 4.7 is installed) and try to run it there, it fails with following exception:

System.InvalidOperationException: Cannot find reference assembly '.NETFramework/v4.7/Microsoft.CSharp.dll' file for package Microsoft.CSharp.Reference

If I copy this dll manually into the bin, the exception continues to appear because of the next dll. I copied: Microsoft.CSharp, mscorlib, System, System.ComponentModel.Composition, System.ComponentModel.DataAnnotations, System.Core, System.Data, System.Drawing, System.IO.Compression.FileSystem, ... So you see it doesn't end.

I also tried these suggestions:

  • adding <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.0" /> to .csproj (https://github.com/dotnet/sdk/issues/1488)
  • adding <DependsOnNETStandard>netstandard2.0</DependsOnNETStandard> to .csproj
  • adding <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish> <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish> to .csproj (Asp.net Core 2.0 with .net framework 4.6.1 - Cannot find reference assembly '.NETFramework/v4.6.1/Microsoft.CSharp.dll)
  • creating a new .NET core 2.0 project with .NET Framework 4.7 and adding MVC. I tested if it would work on the other machine and it did. There were no missing assemblies. -> then I compared this solution to my solution, compared the NuGet packages and Startup.cs, but I could not find anything that was different.

There just has to be something wrong in my project but I'm really clueless now what that could be and I would be extremely thankful if someone could give me some advice.

1
I had the issue with dll .NETFramework/v4.7.2/System.Net.dll, but after adding the suggestions above it worked for me :) Fingers crossed when we have to update this project to 3.x ;-)ArieKanarie
@GeorgeMaharis Were you able to figure this out?ashraydimri
the solution for me was to do it with 'dotnet publish -o C:\temp' instead of the VS release buildGeorgeMaharis

1 Answers

0
votes

Under the assumption that a clean project with mvc (.net 4.7 framework) executes on both the development machine and the production machine then I believe:

  1. Both production and development kestrel web servers are operating correctly.
  2. Clean project .net core 2.0 and .net 4.7 framework are installed and being referenced correctly.
  3. This may indicate that the development project has internal reference paths that are directly linked to development machine paths (sometimes this happens during project development if references are manually added or different package managers are used) instead of dynamically linked in a deployment package.

Next step if I was trying to find the problem would be to change the target for visual studio's release output to the production servers path over a network instead of the development machine or if not network connected then publish a self-contained deployment package (folder based) that you transfer to the production machine and deploy on the web server.

Without more detail this is probably as much as I can help at the moment.

Just a note in the current environment of changing versions and references I have had many of these same issues and I have found a simple solution that may help in future projects. When I add libraries or frameworks that require various mappings for versioning and referencing schema's I create library projects that act as my own wrapper and version control for the framework, deploy that to the package manager and then link that wrapper project to the main project through the package manager. This has the benefit of letting you manage the maintenance (paths and binding) of versioning and referencing yourself instead of it being directly bound to the main project (all references have your own standardized bindings)

Hope this has helped with finding a solution.