2010-04-30 55 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 ...

相關問題