msbuild - 带有 netstandard2.0 引用的 .net 4.8 项目不会通过 msbuild 构建
问题描述
该解决方案在 VS2019 中构建良好,但是当我们的构建代理上的 msbuild 获取我们的解决方案时,它抱怨对我们的几个 dll 的引用。
我刚刚添加了对 NuGet 包的引用,该包引入了 netstandard 2.0 依赖项,所以这似乎是问题所在。
我注意到,如果我进入构建服务器并在 VS FIRST 中构建解决方案......然后相同的 msbuild 命令行将在之后成功。因此,在正常构建情况下,这些 netstandard dll 似乎没有被构建,以便它们可以包含在其他项目编译中。
F:\Agents\MyAgent_work\18\s\src\WS_Reports.metaproj:警告 MSB3268:主要参考“F:\Agents\MyAgent_work\18\b\My.Project\My.Project.dll”无法解析,因为它间接依赖于框架程序集“netstandard,Version=2.0.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”,这在当前目标框架中无法解决。“.NETFramework,版本=v4.8”。要解决此问题,请删除引用“F:\Agents\MyAgent_work\18\b\My.Project\My.Project.dll”或将您的应用程序重新定位到包含“netstandard, Version=2.0.0.0,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51"。
这是 msbuild 引发错误的项目的解决方案文件声明....可以看到项目对错误中显示的 dll 的引用(上面的示例)。请注意,这个项目和我将新的 netstandard2.0 包添加到目标框架 v4.8 的项目
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "WS.Reports", "WebServices\WS.Reports\", "{C47BAAE6-0708-4D43-83B8-92405B31A3E0}"
ProjectSection(WebsiteProperties) = preProject
SccProjectName = "SAK"
SccAuxPath = "SAK"
SccLocalPath = "SAK"
SccProvider = "SAK"
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.8"
ProjectReferences = "{2222173A-112A-44F8-A614-C7CCBDACEFE8}|My.Project.Bus.dll;{222924FE-877B-4E18-B960-94DED3DB6DF2}|MyProject.Protocols.Shared.dll;{222F5846-55E6-4541-B43B-E49674963E02}|MyProject.AuthProtocols.dll;{2224BC03-6C7E-4E15-B158-D9BD03D0E8B3}|My.Project.dll;{222BAF47-1C9F-4A56-9152-B4240A188612}|My.Project.Images.dll;{222FE788-27B1-4B03-B052-BCFFF251C15A}|My.Project.Legacy.dll;"
Debug.AspNetCompiler.VirtualPath = "/WS.Reports"
Debug.AspNetCompiler.PhysicalPath = "WebServices\WS.Reports\"
Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\WS.Reports\"
Debug.AspNetCompiler.Updateable = "true"
Debug.AspNetCompiler.ForceOverwrite = "true"
Debug.AspNetCompiler.FixedNames = "false"
Debug.AspNetCompiler.Debug = "True"
Release.AspNetCompiler.VirtualPath = "/WS.Reports"
Release.AspNetCompiler.PhysicalPath = "WebServices\WS.Reports\"
Release.AspNetCompiler.TargetPath = "PrecompiledWeb\WS.Reports\"
Release.AspNetCompiler.Updateable = "true"
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
VWDPort = "17515"
VWDDynamicPort = "false"
SlnRelativePath = "WebServices\WS.Reports\"
StartServerOnDebug = "false"
EndProjectSection
EndProject
也许我需要抛出错误的项目或带有 netstandard 引用的项目以 v4.8 和 netstandard2.0 为目标?
解决方案
在您的 web.config 文件中,添加对 netstandard 程序集的引用:
<system.web>
<compilation debug="true" targetFramework="4.8">
<assemblies>
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.8" />
...
推荐阅读
- python - 在 Pandas 中复制行并添加一个新的(月)列
- r - 加入 2 个带日期的数据框以扩展到每个单元
- python - 避免mysql中的重复数据
- wordpress - Wordpress - 使用类型为日期的自定义字段在 Elementor 页面中显示帖子
- c++11 - 如何正确比较 Q_ENUM 和 QStringList
- java - 删除 hashmap 中的一个值,而不是所有值和键
- javascript - 使用 addEventListener 创建 Meme Generator(无画布)
- python - 如何在 python 中通过 kwargs 使用 Python 关键字
- ecmascript-6 - 如何使用 ECMAScript 切换 2 个类
- python - 在 django 中使用 MySQL 作为数据库时出错