6
votes

I have recently upgraded my project from asp.net core 1.1 to asp.net core 2.0. and app us using .Net framework 4.6.1. Application is working as expected on local dev machine but once it deployed to server with dotnet publish command I am seeing this error

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

I have also noticed that ref folder that use be present when using asp.net core 1.1 when published is now missing. How to fix this issue.

3
Did you use , --self-contained option while doing a publish?Simsons
No. Should it be used?Praneeth
--self-contained will copy all the dependencies , and it looks te be in your case.Simsons
No its not working even after adding --self-containedPraneeth
Please post the contents of the .csproj file.NightOwl888

3 Answers

6
votes

Same issue was resolved when MvcRazorCompileOnPublish was added to .csproj file.

Give it a try.

<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
2
votes

I noticed if you have the Views folder included with the compiled View.dll when you start your IIS pool, you get this error. I was doing this on purpose for a short term work around hack.

0
votes

In my case (I run .Net core in console application mode) none of above solutions didn't works, i just downloaded .Net Framework 4.6.1 from this link.