简体   繁体   English

如何在VisualStudio 2012中安装Contract-First工具

[英]How to install Contract-First Tool in VisualStudio 2012

I have VisualStudio 2012 and I'm trying to follow the following tutorial http://msdn.microsoft.com/en-us/library/hh674270.aspx 我有VisualStudio 2012,我正在尝试按照以下教程http://msdn.microsoft.com/en-us/library/hh674270.aspx

But I couldn't find the option Schema Definition from the WCF pane of the Templates dialog. 但是我无法从“模板”对话框的WCF窗格中找到“ 架构定义 ”选项。

Do I have to install something? 我必须安装一些东西吗? What would that be? 那会是什么? An extension, perhaps? 也许延伸?

Thanks in advance. 提前致谢。

You don't need to install it - it's already there. 你不需要安装它 - 它已经存在了。 What might be catching you out is that it's only available in the "WCF Service Library" template. 可能会让你感到惊讶的是它只能在“WCF服务库”模板中使用。

VS 2012正确的WCF项目

Once you then add a schema file as shown: 然后,如图所示添加模式文件: 添加XML架构

You then get an additional option on the project properties: 然后,您可以在项目属性上获得其他选项:

在此输入图像描述

I want to add my findings. 我想补充一下我的发现。

I too wanted the Contract-First tool and didn't find the setting mentioned in the msdn link. 我也想要Contract-First工具,但没有找到msdn链接中提到的设置。

However I found out how to add it to any project type as I wanted my iis-hosted services to use contract first aswell. 但是我发现了如何将它添加到任何项目类型,因为我希望我的iis托管服务首先使用契约。

What you do is to create a "WCF Service Library" as mentioned above. 你要做的是创建一个如上所述的“WCF服务库”。

Then open the csproj-file for the project in a text editor. 然后在文本编辑器中打开项目的csproj文件。

Then copy paste the entries that looks something like this into the other project-file 然后将看起来像这样的条目复制粘贴到另一个项目文件中

  <FlavorProperties GUID="{3D9AD99F-2412-4246-B90B-4EAA41C64699}">
    <WcfProjectProperties>
      <AutoStart>True</AutoStart>
    </WcfProjectProperties>
  </FlavorProperties>

Also you need to change the guid:s in the target project to something like this: 您还需要将目标项目中的guid:s更改为:

<ProjectTypeGuids>{3D9AD99F-2412-4246-B90B-4EAA41C64699};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

The FlavorProperties tag with its guids are from vs2012 update 3 so it may change in the future. 带有guid的FlavorProperties标记来自vs2012更新3,因此将来可能会发生变化。

So with this hack you're able to deploy contract first services directly to the iis. 因此,通过此hack,您可以将合同优先服务直接部署到iis。

The question however is why it wasn't working like this out of the box in visual studio 2012 然而问题是为什么它在visual studio 2012中没有开箱即用

You don't need to add the XSD from the WCF pane, just take the XML Schema item from the Data pane. 您无需从WCF窗格添加XSD,只需从“数据”窗格中获取XML Schema项。

If VS 2012 has the option "Enable XSD as type definition language" on, it will generate the types under the namespace of your solution + ".ContractTypes". 如果VS 2012上有“启用XSD作为类型定义语言”选项,它将在解决方案的命名空间+“.ContractTypes”下生成类型。

Check the output windows to see what the build process is doing with the XSDs. 检查输出窗口以查看构建过程对XSD执行的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM