aspnet / Razor

[Archived] Parser and code generator for CSHTML files used in view pages for MVC web apps. Project moved to https://github.com/aspnet/AspNetCore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find reference assembly 'Microsoft.Win32.Primitives.dll' after set RazorCompileOnBuild=false

sergei66666 opened this issue · comments

At first we used .net Core 1.1.2 with <TargetFramework>net461</TargetFramework>.
Now we migrated to .net Core 2.1.5 with <TargetFramework>net472</TargetFramework>.

We have two developer machines (machine A and machine B), both with VS 2017 15.8.7 and installed net472, with the same dotnet --info output:

 Version:   2.1.403
 Commit:    04e15494b6

Среда выполнения:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.403\

Host (useful for support):
  Version: 2.1.5
  Commit:  290303f510

We have problem with views precompilation (I think).

First case. Use this settings

<RazorCompileOnPublish>true</RazorCompileOnPublish>
<RazorCompileOnBuild>true</RazorCompileOnBuild>

All works correctly while debug on both machines (IIS local). If we made any changes to *.cshtml during debug - all works fine on machine A (views recompiled), but on B we get exception:

InvalidOperationException: Cannot find reference assembly 'Microsoft.Win32.Primitives.dll' file for package Microsoft.Win32.Primitives.Reference
Microsoft.Extensions.DependencyModel.Resolution.ReferenceAssemblyPathResolver.TryResolveAssemblyPaths(CompilationLibrary library, List assemblies)

Second case

<RazorCompileOnPublish>true</RazorCompileOnPublish>
<RazorCompileOnBuild>false</RazorCompileOnBuild>

At machine A all works, on B we get the same exception, but at the startup.

We try:

  1. Different combinations of:
<PreserveCompilationContext>true</PreserveCompilationContext>
<CopyRefAssembliesToPublishDirectory>true</CopyRefAssembliesToPublishDirectory>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
  1. Clear nuget cache and restore packages.

Also we try to get exception on machine A but without results - all works fine.

Please, help us find diference between machine A and B, what can be cause of this behavior?

full stack here.txt

commented

Hi. It looks like this is a question about how to use ASP.NET Core. While we do our best to look through all the issues filed here, to get a faster response we suggest posting your questions to StackOverflow using the asp.net-core-mvc tag.

commented

@sergei66666, just a generic advice: try to either repair VS installation on the B machine or just reinstall the 2.1.5 SDK on that machine. It may be your setup somehow got messed up.

commented

@pranavkm, do you have any suggestions regarding the razor compilation aspects here? Thanks!

Setting <CopyRefAssembliesToPublishDirectory>true</CopyRefAssembliesToPublishDirectory> should be the only one that should matter here assuming you are publishing your app.

@pranavkm We did not check what happen on publish, but during debug this flag did not work (no refs folder).

So, for now we went back to net461 and all works fine. We get refs folder during debug and no problems on all machines.

Interesting thing. While using net472 on machine A - we didn't have ref folder, but all works. Strange.

The refs directory is used for runtime compilation for a published application. The intent is that the server the application is deployed to would not have the packages dir or reference assemblies required for view compilation. Debugging generally should not require the refs folder (although there are are a couple of known cases where the folder gets published).

Regardless, this looks like a dup of dotnet/sdk#1738. The fix was made in the SDK v2.1.4 or newer. Could you verify both the machines have the right Sdk installed?

Both have Version: 2.1.403

@sergei66666 was the issue resolved for you?

@pranavkm Yes, after rolling back to net461.