ASP网站项目中的多目标框架问题 [英] Problem with multi target frameworks in asp web site project

查看:75
本文介绍了ASP网站项目中的多目标框架问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了同时针对.NetStandard和.NET标准的C#库框架..NetFramework.这是通过编辑.csproj文件,将TargetFramework更改为TargetFramework s 并将它们都添加到标记中来完成的:

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

我现在可以将此框架添加为我的其他项目中的ProjectReference.

这对于具有.csproj文件的所有项目都非常有用.

但是,当将框架添加到asp网站项目(没有.csproj文件)时,我会遇到一些非常奇怪的构建错误.

 无法获取项目参考"XX.Framework" wwwroot的依赖项类型'System.Enum'在未引用的程序集中定义.您必须添加对程序集"netstandard,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = cc7b13ffcd2ddd51"的引用. 

我的网站的TargetFramework是4.7.1,如我的web.config所示:

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

我从导入的.dll的文件大小中看到,它获取的是.NetStandard的dll,而不是.NetFramework.正确,为什么我会遇到构建错误.

请注意,通过nuget(而不是项目引用)添加框架时,它会获取正确的dll,即.NetFramework dll.因此没有构建错误.

我的问题是这个:为什么在添加多目标框架时,按项目引用,asp.net网站为什么忽略了web.config中的targetFramework?

编辑1 :我的网站结构:

编辑2 :VS解决方案带有示例问题.

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

解决方案

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>

这篇关于ASP网站项目中的多目标框架问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆