我有一个具有以下(简化)结构的解决方案:
Application.sln
|- Business.csproj
|- DAL.vbproj
这两个项目都针对 .NET Framework 4.5.2。它在本地和 VSTS 中构建。
我现在在 DAL 项目中添加了一个 NuGet 包引用到一个 .NET Standard 1.1 dll。它仍然在我的本地机器上完美构建,但不再在 VSTS 上。我收到以下错误:
SGEN : error : An attempt was made to load an assembly with an incorrect format: C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.runtime.interopservices.runtimeinformation\4.3.0\ref\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll. [E:\VstsAgents\2\_work\16\s\Src\Business\Business.csproj]
请注意 VSTS 似乎在抱怨Business.csproj
而不是DAL.vbproj
. 尽管 Business 确实引用了 DAL。
我已经阅读了 .NET Standard 1.1 不支持 SGEN,但是如果生成序列化程序集的选项设置为Auto
,它应该可以工作。我所有的项目都设置为自动。
我还阅读了有关如何更改构建定义的信息,但是
- 我无法更改构建定义
- 我在本地使用相同的配置没有错误(Release,Any CPU)
我应该研究.NET Core Xml Serializer Generator吗?理想情况下,我只想让我的 NuGet 包的构建跳过 SGEN。
更新
将该system.debug
选项设置为 true 可以为我们提供更多信息。我们有一条错误消息:cannot load a reference assembly for execution
。我们还能够在本地复制它。我的机器安装了 .NET 4.7.1 SDK 和目标包,但另一台本地机器没有。安装它修复它。我们现在正在考虑在构建机器上安装它(显然,VSTS 被设置为在本地代理上使用)。
我相信这些是相关的日志行:
2018-02-14T10:03:33.4980817Z ##[error]SGEN(0,0): Error : An attempt was made to load an assembly with an incorrect format: C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.runtime.interopservices.runtimeinformation\4.3.0\ref\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll.
2018-02-14T10:03:33.4980817Z ##[debug]Processed: ##vso[task.logissue type=Error;sourcepath=SGEN;linenumber=0;columnnumber=0;code=;]An attempt was made to load an assembly with an incorrect format: C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.runtime.interopservices.runtimeinformation\4.3.0\ref\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll.
2018-02-14T10:03:33.4980817Z 108>SGEN : error : An attempt was made to load an assembly with an incorrect format: C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.runtime.interopservices.runtimeinformation\4.3.0\ref\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll. [E:\VstsAgents\2\_work\16\s\Src\Business\Business.csproj]
2018-02-14T10:03:33.4980817Z - Could not load file or assembly 'file:///C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.runtime.interopservices.runtimeinformation\4.3.0\ref\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
2018-02-14T10:03:33.4980817Z - Cannot load a reference assembly for execution.
```