gpt4 book ai didi

c# - 针对 4.7.2 的 Asp.net 网站项目无法使用 MSBuild 解析 .netstandard 2.0 引用

转载 作者:太空宇宙 更新时间:2023-11-03 12:04:02 24 4
gpt4 key购买 nike

我有一个 .net 4.0 asp.net 网站(旧网站,没有 .csproj)。这引用了 .net framework 4.0 类库(共享库 A)。

我在解决方案中添加了一个新的 .net 核心 API 项目。该项目还需要与共享库 A 对话。

解决方案(我认为)是将类库移动到 .net standard 2.0,然后将网站移动到 4.7.2,这将允许它引用 .net standard 2.0 项目。

为此,我更改了网站的网络配置,以便:

 <compilation debug="true" targetFramework="4.7.2">
<httpRuntime maxRequestLength="10000" executionTimeout="1000" requestValidationMode="2.0" targetFramework="4.7.2"/>

这一切都适用于 Visual Studio。解决方案构建,网站运行,.netstandard2.0 库中的代码按预期运行并且是可调试的。我知道 Visual Studio 在做一些与 MSBuild.exe 不同的事情。

问题是我们的 CI 服务器无法构建解决方案,本地“MSBuild.exe”也不能。

我正在运行的命令是:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" "[Path to Solution]\AT3.sln"

然后我得到错误:

 warning MSB3268: The primary reference "C:\Work\AT3\at3\wrld\AT3.Common.Utilit ies\bin\Debug\netstandard2.0\AT3.Application.Utilities.dll" could not be resolved because it has an indirect depende ncy on the framework assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" which  could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.7.2". To resolve this problem,  either remove the reference "C:\Work\AT3\at3\wrld\AT3.Common.Utilities\bin\Debug\netstandard2.0\AT3.Application.Uti lities.dll" or retarget your application to a framework version which contains "netstandard, Version=2.0.0.0, Cultur e=neutral, PublicKeyToken=cc7b13ffcd2ddd51"

为了尝试解决这个问题,我在我的 web.config 部分添加了以下行:

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

我的问题是:我怎样才能使用 MSBuild.exe 解决这个 .netstandard2.0 项目?一个网站真的可以是“4.7.2”并成功引用 .net 标准,还是 visual studio 说它可以在骗我?

注意事项:我知道我们需要将网站移至 Web 项目。我只是希望这不是解决这个问题的唯一方法,因为它有点像一个单一的网站。我们的计划是开始慢慢地将 App_Code 中的代码迁移到 .netstandard2.0 库中。

提前谢谢你。

最佳答案

我刚从同事那里得知。

您可以尝试在 .Net Standard 库的 csproj 文件中添加引用,如下所示。这对我有用。

<Reference Include="netstandard">
<Private>True</Private>
</Reference>

关于c# - 针对 4.7.2 的 Asp.net 网站项目无法使用 MSBuild 解析 .netstandard 2.0 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55899488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com