github / VisualStudio

GitHub Extension for Visual Studio
https://visualstudio.github.com
MIT License
2.38k stars 1.2k forks source link

ASP.NET MVC 5 Razor View Errors with Multi Target Project References #2500

Open wjchristenson2 opened 4 years ago

wjchristenson2 commented 4 years ago

Versions

What happened

In an effort to start migration to .NET Core, we converted our class library projects to dual target NetCore 3.1 and Full 4.7.2. We've added our dual target class libraries as project references to the 4.7.2 MVC 5 web project. Everything compiles and runs fine. However, when editing our Razor views in Visual Studio, we get .NET Core errors when referencing objects in our dual target projects. The razor view editor appears to be using the NetCore 3.1 target instead of 4.7.2... If you drill-into an object reference in the razor view, it goes to the Core 3.1 flavor of our object instead of our full framework version.

Errors like: "The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runetime, Version=4.2.2.0....'. The type 'HttpRequest' is defined in an assembly that is not referenced... 'Microsoft.AspNetCore.Http.Abstractions'. etc. All related to our web project not having .NET Core references which shouldn't be a thing.

Our web project is targeting 4.7.2. We have manually edited the web projects' project references to utilize the AdditionalProperties="TargetFramework=net472" and SetTargetFramework to TargetFramework=net472. We have 4.7.2 set in the web.config for compliation and httpRuntime.

`

{079c59ed-768b-4176-b189-56c8e53c329b}
  <Name>xxx.Web</Name>
  <SetTargetFramework>TargetFramework=net472</SetTargetFramework>
</ProjectReference>`

Any help would be much appreciated. Thank you.

wjchristenson2 commented 4 years ago

This is still an issue. Anyone have any insight into how to resolve? Thanks.