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.