简体   繁体   English

MSBuild 无法使用 Bcl 相关库构建网站

[英]MSBuild fail to build web site with reference a Bcl related library

I have 2 projects (.Net 4.0)我有 2 个项目(.Net 4.0)

  • A class library (DataProvider)一个类库(DataProvider)
    • Add reference to Bcl.Async library (via nuget)添加对 Bcl.Async 库的引用(通过 nuget)
    • Provide some async methods提供一些异步方法
  • A web site (SampleSite)一个网站(SampleSite)
    • Reference to "DataProvider"参考“数据提供者”

The problem:问题:

  • When I build with Visual studio, everything is fine (I use VS 2017 Community)当我使用 Visual Studio 构建时,一切都很好(我使用 VS 2017 Community)
  • When try with MSBuild (MSBuild /target:rebuild /p:Configuration=Release /m:4), I get this warning "..\\WebSite1_1_.metaproj" (Rebuild target) (2) -> ..\\WebSite1_1_.metaproj : warning MSB3268: The primary reference "...\\WebSite1\\DataProvider\\bin\\Debug\\DataProvider.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework.尝试使用 MSBuild (MSBuild /target:rebuild /p:Configuration=Release /m:4) 时,我收到此警告“..\\WebSite1_1_.metaproj”(重建目标)(2) -> ..\\WebSite1_1_.metaproj :警告 MSB3268:无法解析主要引用“...\\WebSite1\\DataProvider\\bin\\Debug\\DataProvider.dll”,因为它间接依赖于框架程序集“System.Runtime, Version=1.5.11.0, Culture=中性,PublicKeyToken=b03f5f7f11d50a3a”,在当前目标框架中无法解决。 ".NETFramework,Version=v4.0". “.NETFramework,版本 = v4.0”。 To resolve this problem, either remove the reference "...\\WebSite1\\DataProvider\\bin\\Debug\\DataProvider.dll" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"."要解决此问题,请删除引用“...\\WebSite1\\DataProvider\\bin\\Debug\\DataProvider.dll”或将您的应用程序重定向到包含“System.Runtime, Version=1.5.11.0, Culture=neutral”的框架版本, PublicKeyToken=b03f5f7f11d50a3a"。"
  • The latest DataProvider dll won't be copied to the Bin folder of "SampleSite", if I use some thing new from DataProvider I will get error (build fail)最新的 DataProvider dll 不会被复制到“SampleSite”的 Bin 文件夹中,如果我使用来自 DataProvider 的一些新东西,我会得到错误(构建失败)

I have searched around, including StackOverFlow.我四处搜索,包括 StackOverFlow。 But I can't find anything related to my scenario.但是我找不到与我的场景相关的任何内容。

I tried:我试过:

(no code for this question) (这个问题没有代码)

My expectation:我的期望:

  • I can use MSBuild or something automatically to solve this problem (because this issue is happened on my build server, automatically)我可以自动使用 MSBuild 或其他东西来解决这个问题(因为这个问题是在我的构建服务器上自动发生的)

Update images更新图片

  • Solution解决方案解决方案结构
  • Just added new property to DataProvider:刚刚向 DataProvider 添加了新属性: 添加新属性
  • Use it normally on Website:在网站上正常使用它: 参考好吧
  • MSBuild output: MSBuild 输出: 输出
  • DataProvider project:数据提供者项目: 在此处输入图片说明

If I Right-Click on "WebSite2" -> Build web site, everything will be fine.如果我右键单击“WebSite2”-> 构建网站,一切都会好起来的。 But I want to use msbuild for automation job但我想使用 msbuild 进行自动化工作

I can now reproduce same issue in my machine(details see #4594), since it has some difference from #5993 , I report it in msbuild instead of dotnet cli .我现在可以在我的机器上重现相同的问题(详细信息参见 #4594),因为它与#5993有一些不同,我在msbuild而不是dotnet cli报告它。 Issue reported to Msbuild 4594 .问题已报告给Msbuild 4594

And a workaround which can work in command-line is to use devenv commands.可以在命令行中工作的解决方法是使用devenv命令。

But it requires us to install VS in build machine, then we can use devenv command like:但是它需要我们在构建机器中安装VS ,然后我们可以使用devenv command例如:

在此处输入图片说明

Use the -Rebuild switch can works well like what it behaves in VS.使用-Rebuild开关可以像它在 VS 中的行为一样工作。 See Remark1 .备注1

In my opinion, if we build this specific solution in vs, it may make more actions behind than single msbuild.exe does.在我看来,如果我们在 vs 中构建这个特定的解决方案,它可能会比单个 msbuild.exe 执行更多的操作。 And that's why it works well in vs but not msbuild command-line.这就是它在 vs 中运行良好但在 msbuild 命令行中运行良好的原因。

So if we need to automatically build this particular website in build server, we can try to use devenv command.(To see build output,it seems using devenv.com is better than using devenv.exe , see this )所以如果我们需要在构建服务器中自动构建这个特定的网站,我们可以尝试使用 devenv 命令。(要查看构建输出,似乎使用devenv.com比使用devenv.exe更好,请参阅

Hope it makes some help and let's track the issue in 4594.希望它能有所帮助,让我们在 4594 中跟踪问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM