从VS2008升级到VS2010后SGEN不起作用
我最近刚刚将 VS2008/.NET 3.5 SP1 项目升级到 VS2010 和 .NET 4。我有一个生成后事件,它调用 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 时遇到相同的错误,但我无法弄清楚问题是什么。有什么想法吗?
I just recently upgraded a VS2008/.NET 3.5 SP1 project to VS2010 and .NET 4. I have a post-build event which calls SGEN to generate the XmlSerializers assembly.
Whenever I try to run it I get the following error.
"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 /?".
I get the same error running SGEN from the command line, but I can't figure out what the problem is. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎 SGEN 的第二行输出很重要:
我发现了 SGEN 的另一个版本,它似乎可以在 C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\sgen.exe 中工作。当您运行它时,它会输出以下内容:
我不确定为什么两者都包含在 Windows 7 SDK 中...
Seems like that second line of output from SGEN is important:
I found another version of SGEN which seems to work at
C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\sgen.exe
. It outputs this when you run it:I'm not sure why both are included in the Windows 7 SDK...
是的,sgen.exe 有两个版本可用,一种用于 CLR v2 程序集,另一种用于 CLR v4 程序集。它会爆炸,因为您要求 v2 版本的 sgen.exe 处理 v4 程序集。
检查您的项目如何启动 sgen.exe。如果这是构建后事件,那么您必须调整 sgen.exe 的路径。我没有看到宏或环境变量可以自动使其正确,有点疏忽。
Yes, there are two versions of sgen.exe available, one for CLR v2 assemblies, the other for CLR v4 assemblies. It bombs because you ask the v2 version of sgen.exe to process a v4 assembly.
Check how your project gets sgen.exe started. If it is a post-build event then you'll have to tweak the path to sgen.exe. I don't see a macro or environment variable to get it right automatically, bit of an oversight.