Problem with multi target frameworks in asp web site project

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 01:41:50

问题


I have developed a C# Library Framework that targets both .NetStandard & .NetFramework. This was done by editing the .csproj file, changing TargetFramework to TargetFrameworks and adding both of them in the tag:

<TargetFrameworks>netstandard2.0;net471</TargetFrameworks>

I'm now able to add this framework as a ProjectReference in my other projects.

This works great for all projects that have a .csproj file.

However when adding the framework to an asp web site project (That does not have a .csproj file), I get some very strange build errors.

Could not get dependencies for project reference 'XX.Framework' wwwroot    

The type 'System.Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

My TargetFramework for the web site is 4.7.1, as seen in my web.config:

<compilation debug="true" targetFramework="4.7.1">

I see from the file size of the imported .dll, that it is getting the dll for .NetStandard not .NetFramework. Properly why I'm getting build errors.

Note that when adding the framework via nuget, instead of project reference, it does get the correct dll, meaning the .NetFramework dll. And therefor no build errors.

My question is this: Why is asp.net web sites ignoring my targetFramework in web.config, when adding multi target frameworks, by project reference?

Edit 1: My website structure:

Edit 2: VS solution with an example of the problem. https://github.com/srenrd/MultiFrameworkExample


回答1:


Per the sample code, please add the following code into the Web.config file:

<assemblies>
    <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
  </assemblies>



来源:https://stackoverflow.com/questions/55373711/problem-with-multi-target-frameworks-in-asp-web-site-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!