2010-04-30 49 views
6

我刚刚将一个VS2008/.NET 3.5 SP1项目升级到了VS2010和.NET 4.我有一个生成后事件,它调用SGEN生成XmlSerializers程序集。从VS2008升级到VS2010后,SGEN无法工作

每当我尝试运行它时,我会收到以下错误消息。

"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得到相同的错误,但我找不出什么问题。有任何想法吗?

回答

2

是的,有sgen.exe的两个版本,一个是CLR v2程序集,另一个用于CLR v4程序集。它因为你问v2版本的sgen.exe来处理v4程序集而炸弹。

检查您的项目如何获取sgen.exe启动。如果它是一个生成后事件,那么你将不得不调整sgen.exe的路径。我没有看到一个宏或环境变量自动地让它正确,有点疏忽。

8

好像从SGEN输出的是第二条线是非常重要的:

[Microsoft (R) .NET Framework, Version 2.0.50727.3038] 

我发现SGEN的另一个版本,这似乎在C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\sgen.exe工作。它输出这个当你运行它:

[Microsoft (R) .NET Framework, Version 4.0.30319.1] 

我不知道为什么都被包含在Windows 7 SDK ...

相关问题