- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 TeamCity 中的 MSBuild 运行程序来构建 ASP.net Web API 并运行单元测试。一切正常,直到我升级到“Microsoft Build Tools 2017 15.7.2”。
msbuild 突然从“C:\Program Files (x86)\ISS\Microsoft Web Deploy V3”或“C:\Program Files\ISS”复制旧版本的 Newtonsoft.Json.dll(版本 6.0.4.17603)\Microsoft Web Deploy V3”在构建解决方案时添加到输出文件夹。所有项目都使用 NuGet 引用 9.0.1 版本。
在构建运行时监视输出文件夹,我可以看到 .dll 在 6.0.4 和 9.0.1 之间来回切换,直到构建结束,而 6.0.4 版本仍然存在。
我找到了 this question当我将 Web 部署文件夹中的 Newtonsoft.Json.dll 文件重命名为 Newtonsoft.Json_old.dll”时,msbuild 没有替换我的 9.0.1 版本并且一切正常。
我已检查所有引用 Newtonsoft.Json 的项目都引用 9.0.1 版本并在 .csproj 文件中使用正确的提示路径。
有没有人知道如何解决这个问题?我的解决方案似乎更像是一种解决方法,我想知道为什么 msbuild 首先要复制此文件。
最佳答案
总结
当 MSBuild 解析程序集时,它会在一些非常奇怪的目录中搜索,包括 Web Deploy 文件夹,具体取决于您安装的内容。根据 MSBuild 引用,我认为这是遗留行为。您可以使用项目文件中定义的 MSBuild 属性来阻止它执行此操作。
在受影响的项目文件中,找到以下行:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
并在下面添加:
<PropertyGroup>
<AssemblySearchPaths>$(AssemblySearchPaths.Replace('{AssemblyFolders}', '').Split(';'))</AssemblySearchPaths>
</PropertyGroup>
这将导致 MSBuild 在解析程序集时不再查找有问题的文件夹。
全文
当我们迁移到 Visual Studio 2019 时,我的团队遇到了类似的问题。我们的一些项目仍然以 .NET Framework 4.0 为目标,并且在我们的构建代理上安装 Visual Studio 2019 后,我们开始遇到一个神秘的项目错误引用了我们的一些核心库:
The primary reference "OurCoreLibrary, Version=3.4.2.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the assembly "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
将项目切换到目标 4.5 后问题就消失了,但由于我不会在这里详述的原因,我们无法对每个受影响的项目都这样做,所以我决定深入挖掘一下。
事实证明,您的问题让我们对正在发生的事情有了一些了解。我们引用的 Newtonsoft.Json 版本与“C:\Program Files (x86)\IIS\Microsoft Web Deploy V3”中的版本匹配,当我删除该文件时,构建成功。
我们的具体问题是 Web Deploy 文件夹中的 Newtonsoft.Json 副本是同一版本 (9.0.0.0),但框架错误(4.5 而不是 4.0),无论出于何种原因,解析逻辑都不会检查目标框架,导致构建时不匹配。更新到 VS2019 涉及更新 Web Deploy,这也将 Newtonsoft.Json 的副本更新到 9.0.0.0,导致我们发生冲突。
为了了解为什么甚至开始查看该程序集,我将 MSBuild 项目构建输出详细程度设置为诊断并查看发生了什么。搜索有问题的路径表明,在 ResolveAssemblyReferences 任务中,MSBuild 正在通过一些意想不到的地方来寻找匹配项:
1> For SearchPath "{AssemblyFolders}". (TaskId:9)
1> Considered "C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\140\OurCoreLibrary.winmd", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\140\OurCoreLibrary.dll", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\140\OurCoreLibrary.exe", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\OurCoreLibrary.winmd", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\OurCoreLibrary.dll", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\OurCoreLibrary.exe", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\OurCoreLibrary.winmd", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\OurCoreLibrary.dll", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\OurCoreLibrary.exe", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\OurCoreLibrary.winmd", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\OurCoreLibrary.dll", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\OurCoreLibrary.exe", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\OurCoreLibrary.winmd", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\OurCoreLibrary.dll", but it didn't exist. (TaskId:9)
1> Considered "C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\OurCoreLibrary.exe", but it didn't exist. (TaskId:9)
进一步挖掘表明,搜索的路径作为 AssemblySearchPaths
传入,定义在 Microsoft.Common.CurrentVersion.targets 中:
<AssemblySearchPaths Condition=" '$(AssemblySearchPaths)' == ''">
{CandidateAssemblyFiles};
$(ReferencePath);
{HintPathFromItem};
{TargetFrameworkDirectory};
$(AssemblyFoldersConfigFileSearchPath)
{Registry:$(FrameworkRegistryBase),$(TargetFrameworkVersion),$(AssemblyFoldersSuffix)$(AssemblyFoldersExConditions)};
{AssemblyFolders};
{GAC};
{RawFileName};
$(OutDir)
</AssemblySearchPaths>
根据MSBuild Task Reference for the ResolveAssemblyReferences task , SearchPaths
参数定义为:
Specifies the directories or special locations that are searched to find the files on disk that represent the assemblies. The order in which the search paths are listed is important. For each assembly, the list of paths is searched from left to right. When a file that represents the assembly is found, that search stops and the search for the next assembly starts.
...它定义了一些特殊常量,包括我们的 friend {AssemblyFolders}
:
- {AssemblyFolders}: Specifies the task will use the Visual Studio.NET 2003 finding-assemblies-from-registry scheme.
因为目录是按顺序检查的,您可能希望 {HintPathFromItem}
优先,在大多数情况下确实如此。但是,如果您的依赖项依赖于旧版本的 Newtonsoft.Json,则不会有 HintPath 该版本,因此它将继续存在,直到它解决。
Later on in Microsoft.Common.CurrentVersion.targets我们可以看到有些情况下这个常量被显式删除,这就是上面答案的来源:
<PropertyGroup Condition="'$(_TargetFrameworkDirectories)' == '' and '$(AssemblySearchPaths)' != '' and '$(RemoveAssemblyFoldersIfNoTargetFramework)' == 'true'">
<AssemblySearchPaths>$(AssemblySearchPaths.Replace('{AssemblyFolders}', '').Split(';'))</AssemblySearchPaths>
</PropertyGroup>
删除此常量会从考虑中删除有问题的文件夹,老实说,我想不出我希望程序集隐式解析为 Newtonsoft.Json 在 Web 部署中闲逛的任何版本的情况,或者SQL Server SDK 文件夹。话虽这么说,但我确信在某些情况下关闭此功能会导致某些人出现问题,因此请记住这一点。
关于c# - MSBuild 正在用旧版本替换 Newtonsoft.Json.dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50638711/
我想对一个字符串执行搜索和替换,比如 password。 正如您从问题中了解到的那样,替换后的字符串应变为 sdvvzrug。 但不幸的是,下面的代码输出bbbbcaab: $search = ran
我正在使用 futurize --stage2它应用了许多源代码转换以使代码 python2 和 python3 兼容。其中一个修复是所有分区 a/b 都替换为 old_div(a/b),我想避免这种
我正在使用 RStudio,但我在控制台上的输出被截断了。我找不到如何停止截断(我尝试搜索 ?options 以及在谷歌上搜索的时间比我想承认的要长)。 编辑:我向大家道歉!我最初的长名称为“This
我有一个 fragment 堆栈,我在其中使用替换和相加。添加或替换我的 fragment 的代码(在我的 Activity 中)如下 private fun addFragment(fragment
我在一个数组中插入了一些字符串,但在我这样做之前,我想按照主题所说的去做。只用 %20 替换空格,我这样做: Name.push(linkText.replace(" ", "%20")); 但是我如
我正在尝试编译和测试我在网上看到的代码 Expanding an IP add 。但是,当我尝试编译它时,我收到有关 StringBuilder 替换方法的错误。它说: IPadd.java:52:
我正在尝试使用 dplyr 的最新功能重写我的部分代码,方法是将 data.frame() 替换为 data_frame() 和 cbind() 与 bind_cols(): library(rgeo
我最近偶然发现了 replace()和 "[ x.tst s.tst s.tst [,1] [,2] [,3] [1,] 0 0 0
我一直想知道,如何在给定的参数内进行替换。 如果你有这样的一行: 123,Hello,World,(I am, here), unknown 你想更换 World与 Foobar那么这是一个简单的任务
如何转义字符串中的双引号?例如, input: "Nobody" output: \"Nobody\" 我尝试过这样的操作,但不起作用: String name = "Nobody"; name.r
我正在做类似的事情: SQL sql sQl SqL var ps = document.getElementsByTagName('p'); for(var i = 0; i 但它不会替换文本。
我正在尝试用 \" 替换所有 " 并用 JSON 解析字符串,但浏览器抛出错误 SyntaxError: JSON Parse error: Unrecognized token '\'. 下面是代码
大家好,在这里挣扎...... 是否可以将第一个正斜杠之间的任何内容替换为“”,但保留其余部分? 例如var 将是 string "/anything-here-this-needs-to-be-re
在下面的代码中,JavaScript 替换函数中的 alert(a) 将提醒匹配的字符串,在本例中,将是 {name} 和 {place}。 这按照文档 javascript docs 的描述工作,即
+-----------------------------+ | tables | +-------------------
我正在尝试用\"替换包含 "的字符串,下面是我尝试过的程序 String s="\"/test /string\""; s = s.replaceAll("\"", "\\\"");
var text = "a's ..a's ...\"... "; text = convert(text); function convert( text ) { var n = text
我正在尝试使用 JavaScript 中的替换函数,但有一个问题。 strNewDdlVolCannRegion = strNewDdlVolCannRegion.replace(/_existing
好吧,首先我对我的上一篇文章感到非常抱歉,但我真的需要帮助,我会把我真正想要的东西放在一个更清晰的代码中。我不擅长 javascript,所以希望你能帮助我。
我正在写一张纸条,遇到了障碍。可能有更有效的方法来执行此操作,但我对 Python 还很陌生。我正在尝试创建用户生成的 IP 地址列表。我正在使用 print 来查看生成的值是否正确。当我运行此代码时
我是一名优秀的程序员,十分优秀!