4
votes

I have projects with localized resources and x64 native dependencies. Is there any way to build them without warnings?

If I set the target platform to AnyCPU I get this warning because of the native references:

warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Native64", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

OK fair enough, but:

If I set the target platform to x64 I get this warning, because localized resources automatically create a satellite assembly with the wrong target architecture:

ALINK : warning AL1073: Referenced assembly 'mscorlib.dll' targets a different processor

Microsoft says it's a bug, but they wont fix it.

So now what?

1
This is not simple to fix for Microsoft, ALINK has many uses, not just building assemblies without code. The kind where the warning isn't useful. You'd have to take over the building of the satellite assemblies yourself so you can use the 64-bit version of al.exe. Technically possible, not practical.Hans Passant
How would that work? Why is it not practical?Peter
(Why is it not a simple fix? Can't they just build these satellite assemblies as x64? Why would the 64-bit version of al.exe be needed?)Peter

1 Answers

5
votes

Here is a workaround:

The issue can be avoided by using the AL.EXE that matches the platform (or bitness) you are attempting to build. That is, you'll see that when you are building x64, that it is trying to use AL.EXE at a path similar to

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools

If you can get it to use the x64 version of AL.exe, the issue will go away. That is, use the AL.EXE at a path similar to:

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\x64

Msbuild finds this path by using its TargetFrameworkSDKToolsDirectory. Thus, using the assumption that this directory is the correct directory when building x86, the workaround below essentially appends the x64 sub directory on to the path when building x64 and leaves it as is otherwise:

  1. Create an MsBuildAL1073WarningWorkaround.targets file (name doesn't matter) and add it to the project. It has the following contents:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <TargetFrameworkSDKToolsDirectory Condition=" '$(PlatformTarget)' == 'x64'">$(TargetFrameworkSDKToolsDirectory)$(PlatformTarget)\</TargetFrameworkSDKToolsDirectory>
      </PropertyGroup>
    </Project>  
    
  2. Edit the .csproj file to import this file near the end of the file (where you'll see the comment that says "To modify your build process...":

     <Import Project="MsBuildAL1073WarningWorkaround.targets" />
     <!-- To modify your build process... -->