代码改变世界

VS2010不能编译.Net3.5项目的解决方法

2011-05-04 23:10  贼寇在何方  阅读(1610)  评论(1编辑  收藏  举报

用VS2010创建了一个.Net 3.5的Winform项目,结果编译失败,这个问题也算是第二次碰到了,真纠结···
这次不再偷懒了,把解决方法记录下来吧

在64位的Windows 7下,用VS2010编译4.0以前的.Net项目会有问题。原因么,是一个叫Resgen.exe的玩意儿,是跑在64位环境下的,当他试图加载32位的可执行代码时,就会执行失败:

Failed to execute command:
""C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ResGen.exe" (此处省略···)

 

解决方法:
按照官方的解决方法,直接翻译过来

1. 关闭Visual Studio。

2. 在Visual Studio Tools子目录,以管理员身份运行Visual Studio Command Prompt (2010),切换目录到"<system_drive>:\Program Files (x86)\Microsoft SDKs\Windows\v<x.xx>\bin\”. ( 我的是v7.0A )

3. 执行命令:
corflags /32bit+ ResGen.exe /force

4. 在记事本中打开 <project_name>.csproj 文件

5. 添加这个属性在PropertyGroup下面: <ResGenToolArchitecture>Managed32Bit</ResGenToolArchitecture>,然后保存文件。

再次尝试编译,一切OK!

 

参考链接:
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.