我刚刚将VS2008/.NET 3.5 SP1项目升级到VS2010和.NET4。我有一个生成后事件,该事件调用SGEN生成XmlSerializers程序集。

每当我尝试运行它时,都会出现以下错误。

"C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\sgen.exe" /debug /force /verbose /c:"platform:x86" "C:\path\to\SomeAssembly.dll"
Microsoft (R) Xml Serialization support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Error: An attempt was made to load an assembly with an incorrect format: c:\path\to\someassembly.dll.
  - Could not load file or assembly 'file:///c:\path\to\someassembly.dll'
or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

If you would like more help, please type "sgen /?".

我从命令行运行SGEN时遇到相同的错误,但是我无法弄清楚问题出在哪里。有任何想法吗?

最佳答案

是的,有两个版本的sgen.exe,一个用于CLR v2程序集,另一个用于CLR v4程序集。它之所以炸弹是因为您要求sgen.exe的v2版本处理v4程序集。

检查您的项目如何启动sgen.exe。如果是构建后事件,则必须调整sgen.exe的路径。我看不到一个宏或环境变量来自动使它正确,这有点疏忽。

关于visual-studio-2010 - 从VS2008升级到VS2010后,SGEN无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2746372/

10-11 06:56