VS 升级后互操作库上的 corflags 出现问题
我将我的 Visual Studio 解决方案从 2008 年转换为 2010 年。一个项目引用了 ShDocVw。当我运行该程序时,我收到 BadImageFormatException。谷歌搜索引导我使用 corflags 检查互操作库:
corflags Interop.ShDocVw.dll
Version : v2.0.50727
CLR Header: 2.5
PE : PE32
CorFlags : 3
ILONLY : 1
32BIT : 1
Signed : 0
果然,设置了 32BIT 标志,因此我的应用程序构建为 64 位计算机上的任何 CPU 都无法加载此库。如果我运行 corflags /32BIT- 我可以关闭 32BIT 标志,一切正常。问题是,为什么这个互操作库是使用该标志集生成的?我在 VS2008 上没有这个问题,升级后才开始出现这个问题。
更重要的是,我该如何修复它,以便我不必运行 corflags 来关闭该位?我认为这可能是由于一些我不太了解的 MSBuild-fu 造成的。无论如何,我没能发现任何东西。
I converted my visual studio solution from 2008 to 2010. A project has a reference to ShDocVw. When I run the program I get a BadImageFormatException. Googling led me to check the interop library with corflags:
corflags Interop.ShDocVw.dll
Version : v2.0.50727
CLR Header: 2.5
PE : PE32
CorFlags : 3
ILONLY : 1
32BIT : 1
Signed : 0
Sure enough, the 32BIT flag is set so my application built as Any CPU on 64-bit machine cannot load this library. If I run corflags /32BIT- I can turn off the 32BIT flag and everything works just fine. The question is, why is this Interop library generated with that flag set? I didn't have that problem with VS2008, this only started happening after the upgrade.
More importantly, how can I fix it so that I don't have to run corflags to turn the bit off? I assume that it is probably due to some MSBuild-fu that I don't understand very well. I haven't been able to spot anything, anyway.
问题是升级后,C# 项目文件中的某些 中未设置 标记,并且它显然默认为 x86。因此,要解决此问题,请转到项目属性 -> “构建”选项卡并将“平台目标”设置为 AnyCPU 以外的其他值,然后保存。现在将其设置回 AnyCPU 并保存。 将使用 AnyCPU 的值写入项目,一切顺利。
这是我找到答案的地方.
The problem is that after the upgrade the <PlatformTarget> tag is not set in certain <PropertyGroups> in the C# project files and it apparently defaults to x86. So, to fix this go to the project Properties -> Build tab and set Platform Target to something other than AnyCPU, save it. Now set it back to AnyCPU and save it. The <PlatformTarget> will be written to the project with the value of AnyCPU and all is well.
Here is where I found the answer.