Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

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

Closed
sergei66666 opened this issue Oct 22, 2018 · 9 comments
Assignees
Labels

Comments

@sergei66666
Copy link

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

@mkArtakMSFT
Copy link
Member

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.

@mkArtakMSFT
Copy link
Member

@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.

@mkArtakMSFT
Copy link
Member

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

@pranavkm
Copy link
Contributor

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

@sergei66666
Copy link
Author

sergei66666 commented Oct 26, 2018

@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.

@pranavkm
Copy link
Contributor

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?

@sergei66666
Copy link
Author

Both have Version: 2.1.403

@pranavkm
Copy link
Contributor

@sergei66666 was the issue resolved for you?

@sergei66666
Copy link
Author

@pranavkm Yes, after rolling back to net461.

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

No branches or pull requests

3 participants