简体   繁体   中英

C# 7.0 MSbuild unknown build error referencing native dll

I have a .net4.5 project that is built from console by calling msbuild. Now, the build directory can contain (if not doing a clean build) additional native 32bit and 64bit dll files.

Until now the project was being compiled using C# 5.0 (VS2013) and had no issues. I recently switched the project to compile using C# 7.0 (VS2017) and started receiving errors when the build directory contains native dlls (XXXX - redacted paths):

Error: Command: "/cygdrive/C/XXX/4.0/15.0/Bin/MSBuild.exe c:/cygwin/home/XXXX/proj\my_project.csproj
  /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=c:/XXXX/my_project.snk
  /p:FrameworkPathOverride=c:/XXXX/.NETFramework/v4.5"

Microsoft (R) Build Engine version 15.5.180.51428 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 28-Jul-20 20:54:25.
Project "c:\cygwin\home\XXXX\proj\my_project.csproj" on node 1 (default targets).
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9): error MC1000: Unknown build error,
'Could not load file or assembly 'file:///c:\cygwin\home\XXXX\proj\native32or64bit.dll' or one of its dependencies.
The module was expected to contain an assembly manifest.'  [c:\cygwin\home\XXXX\proj\my_project.csproj]
Done Building Project "c:\cygwin\home\XXXX\proj\my_project.csproj" (default targets) -- FAILED.

When running msbuild with /v:d I get the following:

.....
Task "MarkupCompilePass1"
  
  Microsoft (R) Build Task 'MarkupCompilePass1' Version '4.8.3761.0 built by: NET48REL1'.
  Copyright (C) Microsoft Corporation 2005. All rights reserved.
  
  Current project directory is 'c:\cygwin\home\XXXX\proj\'.
  Analysis Result : 'All'.
  Recompiled XAML file : 'c:\cygwin\home\XXXX\proj\my_view.xaml'.
  // other XAML files.....
  Started the markup compilation.
  OutputType is 'library'.
  Input: Assembly Reference file: 'c:\cygwin\home\XXXX\proj\my_util.dll'.
  Input: Assembly Reference file: 'c:\XXXX\.NETFramework\v4.5\mscorlib.dll'.
  Input: Assembly Reference file: 'c:\cygwin\home\XXXX\proj\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll'.
  Input: Assembly Reference file: 'c:\XXXX\.NETFramework\v4.5\PresentationCore.dll'.
  Input: Assembly Reference file: 'c:\XXXX\.NETFramework\v4.5\PresentationFramework.dll'.
  Input: Assembly Reference file: 'c:\XXXX\.NETFramework\v4.5\System.Configuration.dll'.
  Input: Assembly Reference file: 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll'.
  // other managed dll dependencies
  ......
  Input: Assembly Reference file: 'c:\cygwin\home\XXXX\proj\native32.dll'.
  Input: Assembly Reference file: 'c:\cygwin\home\XXXX\proj\native64.dll'.
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9): error MC1000: Unknown build error,

So for some reason the C# 7.0 compiler decided take all dlls in the build directory as dependencies even those that are not referenced in the.csproj file.

I'd really appreciate any direction you can give me, this has been stomping me for some time now and doing a clean make every time is starting to be annoying.

Thanks to @PauloMorgado suggestion to use msbuildlog I was able to determine that the dlls were being referenced by ImplicitlyExpandDesignTimeFacades item, and adding <ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades> in my project file seem to resolved the issue.

I've no idea what this item really means or does but it has a long name and undesired side effects. Would appreciate if someone can comment on what it means.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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