用于 .NET 4.0 的 Svcutil.exe?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2690966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Svcutil.exe for .NET 4.0?
提问by D.H.
I was trying to use svcutil.exe to generate proxy classes for a service but when I use the /referenceoption to reference an assembly that is built for .NET 4.0 I get an error.
我试图使用 svcutil.exe 为服务生成代理类,但是当我使用该/reference选项来引用为 .NET 4.0 构建的程序集时,出现错误。
Could not load file or assembly [...] or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
无法加载文件或程序集 [...] 或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载。
So it seems that I am using an old version of svcutil.exe. I am using the one in "C:\Program Files\Microsoft SDKs\Windows\v7.0Awhich was the latest one I could find. Is there a later version somewhere that I am supposed to use?
所以看起来我使用的是旧版本的 svcutil.exe。我正在使用"C:\Program Files\Microsoft SDKs\Windows\v7.0A我能找到的最新版本。我应该在某处使用更高版本吗?
回答by Boris
I had the same issue. If your project is set to use the .NET 4.0 Framework, you must choose the right version of SvcUtil.exe, or it will throw an error: "Could not load..."
我遇到过同样的问题。如果您的项目设置为使用 .NET 4.0 Framework,则必须选择正确版本的 SvcUtil.exe,否则会抛出错误:“无法加载...”
- If you look in "Microsoft SDKs\Windows\v6.0A\Bin", you will see that the version of that exe is "3.0.4506.2152".
- The version of SvcUtil.exe in "Microsoft SDKs\Windows\v7.0A\Bin" is exactly the same, so it threw me for a loop as well.
- 如果您查看“Microsoft SDKs\Windows\v6.0A\Bin”,您将看到该 exe 的版本为“3.0.4506.2152”。
- “Microsoft SDKs\Windows\v7.0A\Bin”中SvcUtil.exe的版本完全一样,所以它也让我循环了。
However, there is another version of SvcUtil.exe located in "Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools" which is version "4.0.30319.1", and if you use it, everything should work.
但是,还有另一个版本的 SvcUtil.exe 位于“Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools”,即版本“4.0.30319.1”,如果您使用它,一切都应该正常。
回答by Sharken
The latest version of the SDK for .Net 4.0 is available at
适用于 .Net 4.0 的最新版 SDK 可在
http://msdn.microsoft.com/en-us/windows/bb980924.aspx
http://msdn.microsoft.com/en-us/windows/bb980924.aspx
svcutil.exe which resides in v7.1/binhas version 3.0.4506.2152.
驻留在v7.1/bin 中的svcutil.exe版本为 3.0.4506.2152。
svcutil.exe which resides in v7.1/bin/NETFX 4.0 Toolshas version 4.0.30319.1.
驻留在v7.1/bin/NETFX 4.0 Tools 中的svcutil.exe版本为4.0.30319.1。
回答by Sharken
Update: Newest version of util is not v7.0 as per:
更新: util 的最新版本不是 v7.0,如下所示:
Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools
Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 工具
SvcUtil.exe v8.0A is now available after installing Visual Studio 2012 (VS 2012)
SvcUtil.exe v8.0A 现在在安装 Visual Studio 2012 (VS 2012) 后可用
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\SvcUtil.exe"
“C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\SvcUtil.exe”
What you really want is the full definition for turning a WSDL file into a service client:
您真正想要的是将 WSDL 文件转换为服务客户端的完整定义:
/n:*,MyCompany.Services.Client /out:IServiceInterface.cs ServiceDefinition.wsdl.xml
/n:*,MyCompany.Services.Client /out:IServiceInterface.cs ServiceDefinition.wsdl.xml
Where service definition.wsdl is obviously the ?wsdl response from any old soap endpoint.
其中service definition.wsdl 显然是来自任何旧soap 端点的?wsdl 响应。
Minions and Trolls remember! Everything is now Async so look for and take advantage of the new Async support generated by v8.0 of SVCUtil.exe
奴才和巨魔记住了!现在一切都是异步的,所以寻找并利用 SVCUtil.exe v8.0 生成的新异步支持
回答by Hans Olsson
According to this link for .Net 4.0 you should use one in C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin.
根据 .Net 4.0 的这个链接,你应该在 C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin 中使用一个。
http://msdn.microsoft.com/en-us/library/aa347733.aspx
http://msdn.microsoft.com/en-us/library/aa347733.aspx
Seems a little strange though, if the one in the v7.0A dir is too old.
看起来有点奇怪,如果 v7.0A 目录中的那个太旧了。
回答by nedruod
Why not rebuild as .NET 3.5 to generate the classes? I suspect the types you're generating classes for don't rely on any .NET 4.0 functionality. The cs files won't care what version the DLL was built for so you can use them in a 4.0 project just fine.
为什么不重建为 .NET 3.5 来生成类?我怀疑您为其生成类的类型不依赖于任何 .NET 4.0 功能。cs 文件不会关心 DLL 是为哪个版本构建的,因此您可以在 4.0 项目中使用它们就好了。
回答by Chris
I'm having the same problem.
我有同样的问题。
Microsoft says that you can only use .Net 4 DLLs with the new SvcUtil that comes wit the latest version of .Net (http://msdn.microsoft.com/en-us/library/aa347733.aspx) but that version seems to be the one you are mentioning above. It won't access .Net 4 DLLs as references at all.
微软表示,您只能将 .Net 4 DLL 与最新版本的 .Net ( http://msdn.microsoft.com/en-us/library/aa347733.aspx)附带的新 SvcUtil 一起使用,但该版本似乎成为你上面提到的那个。它根本不会访问 .Net 4 DLL 作为引用。
回答by D.H.
Answering my own question. The new version of svcutilwill probably come with v7.1 of the Windows SDKthat is released in mid-June.
回答我自己的问题。新版本svcutil可能会与在Windows SDK的7.1版是在六月中旬发布。

