C#程序导入错误("ResGen.exe"已退出)

       在导一个源码到我的VS2010时,编译运行的时候报了"ResGen.exe"已退出,代码为2。这个问题碰到几次了,所以把它给贴一下,点击进入微软官方支持。简单翻译一下:

 

MSBuild4.0或VS2010在X64机器上编译基于.Net Framework3.5,3.0或者2.0的32位应用可能失败。

可能得到以下的错误信息
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.

 

输出框显示“生成失败”。      

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

 

原因:Resge.exe作为Windows SDK的一部分,被标记为MSIL(微软中间语言)因此它作为64位程序运行。它加载32位封装的程序时候会报错。

 

        解决办法:

        1. 关闭所有打开的Visual Studio。

        2. 在Visual Studio Tools 子目录,以管理员身份运行“Visual Studio 命令提示(2010)”。切换目录到

                “<系统驱动>:\Program Files (x86)\Microsoft SDKs\Windows\v<版本号>\bin\

        3. 执行命令:

                corflags /32bit+ ResGen.exe /force

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

        5. 添加以下属性到PropertyGroup下面:

                <ResGenToolArchitecture>Managed32Bit</ResGenToolArchitecture>

            关闭并保存csproj文件。

 

重新编译,一切OK!翻译参考自这里

 

 

你可能感兴趣的:(C#,VS2010,"ResGen.exe"已退出)