MSBuild 4.0 or VS2010 may fail to compile a 32bit application targeted for .Net Framework

MSBuild 4.0 or Visual Studio 2010 may fail to compile a 32-bit application targeted for .Net Framework 3.5, 3.0 or 2.0 on x64 machine.

SYMPTOMS

You are building an application targeted for x86 configuration on x64 machine with Visual Studio 2010. The project contains a resource file referencing a 32-bit assembly. Target Framework selected is 3.5, 3.0 or 2.0.

You may get the following error:

Form1.resx(161,5):error RG0000: Could not load file or assembly '<file_name>' or one of its dependencies. An attempt was made to load a program with an incorrect format. Line 161, position 5.

The diagnostic build-log shows that task “GenerateResource” fails.

Resgen.exe referenced:

"<system_drive>:\Program Files (x86)\Microsoft SDKs\Windows\vx.x\bin\ResGen.exe"

CAUSE

Resgen.exe, which is a part of Windows SDK, is marked as MSIL and hence it will run as a 64-bit process. It will try to load a 32-bit assembly and fail.

RESOLUTION

In order to work-around this issue you may need to perform the following steps:

1. Close all instances of Visual Studio.

2. From the Visual Studio Tools subfolder, open an elevated “Visual Studio Command Prompt (2010)” (using “Run as administrator” option). Change directory to "<system_drive>:\Program Files (x86)\Microsoft SDKs\Windows\v<x.xx>\bin\”.

eg:C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin

3. Issue the command :

corflags /32bit+ ResGen.exe /force

4. Open <project_name>.csproj in notepad.

5. Add the following property <ResGenToolArchitecture>Managed32Bit</ResGenToolArchitecture> under the PropertyGroup section. Save and close the csproj file.

MORE INFORMATION

Note: If, later on, you want to build a .resx file that references a *64* bit assembly targeting v3.5, v3.0 or v2.0 you may have toreverse this workaround before doing so.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值