首页 文章

ServiceReferences.ClientConfig加上慢速猎豹没有变形

提问于
浏览
4

我在VS 2010中有一个silverlight 5项目,并希望根据我的配置更改其配置文件,非常类似于更改Web应用程序的数据库连接字符串 .

我的ServiceReferences.ClientConfig看起来像这样:

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IWcfPortal" closeTimeout="00:10:00"
                openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                maxBufferSize="25000000" maxReceivedMessageSize="25000000" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint name="WcfCslaService" address="http://localhost:22/Services/WcfSlPortal.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWcfPortal"
            contract="WcfPortal.IWcfPortal" />
    </client>
</system.serviceModel>

我的ServiceReferences.MyConfig.ClientConfig文件(通过右键单击自动添加慢速猎豹,添加变换)如下所示:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.serviceModel>
    <client>
        <endpoint name="WcfCslaService" address="http://192.168.0.0:22/Services/WcfSlPortal.svc"
                  binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWcfPortal" contract="WcfPortal.IWcfPortal"
                  xdt:Transform="Replace" />
    </client>
</system.serviceModel>

我的问题是,不是替换整个节点(就像在同一个解决方案中我在web.config中所做的那样),转换不会发生 . 我尝试过清理/重建,手动删除.xap文件,一次构建一个项目 . 如果我查看我的silverlight项目\ bin文件夹并解压缩我的xap文件,它最终包含所有ClientConfig文件,并且主配置文件保持不变 . 我的xap文件中也有一个错误,它突出显示“xdt:Transform”,表示“未声明'http://schemas.microsoft.com/XML-Document-Transform:Transform'属性 . ”

如果我右键单击ServiceReferences.MyConfig.ClientConfig,预览转换它会向我显示它应该是什么(具有更新的IP地址的相同服务) . 另一个疯狂的事情是,这是以前的工作,我不知道我做了什么来打破它(在我去承诺回购之前就破了) . 我已经卸载并重新安装慢速猎豹,重新启动等 .

任何人都知道如何修复此转换工作?

2 回答

  • 2

    如果所有你使用内置的转换机制并挂钩到 BeforeBuildAfterBuild MSBuild目标 .

    ServiceReferences.ClientConfig.Template 我有类似的东西

    <configuration>
      <system.serviceModel>
        <!-- ... -->
        <client>
          <endpoint
            name="Mine"
            address="http://localhost:8080/SomeService.svc"
            binding="basicHttpBinding"
            bindingConfiguration="..."
            contract="..."/>
        </client>
      </system.serviceModel>
    </configuration>
    

    为了替换地址,我使用了变换

    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <system.serviceModel>
        <client>
          <endpoint
            xdt:Locator="Match(name)"
            xdt:Transform="SetAttributes(address)"
            name="Mine" 
            address="http://SomethingElse/Services/SomeService.svc"/>
    

    如果您正在尝试替换整个节点,我还没有尝试过,但是虽然很痛苦,但您可能会删除所有不需要的属性,然后再添加新属性 .

    为了启动创建真实 ServiceReferences.ClientConfig 的转换,我在Silverlight .csproj 文件中有以下内容:

    <Target Name="BeforeClean">
        <Delete Files="ServiceReferences.ClientConfig" />
        <Message Importance="High" Text="***** Deleted generated ServiceReferences.ClientConfig" />
      </Target>
      <Target Name="BeforeBuild" Condition="Exists('ServiceReferences.$(Configuration).ClientConfig')">
        <!-- this is the file that ultimately we want to populate in a .xap, but this is also not version controlled; effectively it's always generated -->
        <Delete Files="ServiceReferences.ClientConfig" />
        <!-- transform the template -->
        <TransformXml Source="ServiceReferences.Template.ClientConfig" Destination="ServiceReferences.ClientConfig" Transform="ServiceReferences.$(Configuration).ClientConfig" />
        <Message Importance="High" Text="***** Generated ServiceReferences.ClientConfig from ServiceReferences.Template.ClientConfig and ServiceReferences.$(Configuration).ClientConfig" />
      </Target>
      <Target Name="AfterBuild" />
    

    其他一些(可能已在您的解决方案中正确设置)“明显”要检查的内容包括:

    • 确保Silverlight项目属性具有正确的 .xap 名称并生成Silverlight清单文件 .

    • 确保Silverlight应用程序的Web主机项目包含上述项目的名称,并且它位于 ClientBin 中,用于Web中的路径 .

    • 确保两个项目的依赖关系和构建顺序正确

  • 2

    感谢Kit的帮助 . 我终于有一点时间来研究这个并使用不同的配置部署到几个不同的服务器,并提出了以下解决方案:

    • 确保Web项目属性构建输出路径为\ bin \,并且在项目属性的Silverlight应用程序部分中将配置特定文件夹设置为否

    • 确保Silverlight项目属性构建输出路径为\ bin \(这是我的第一个问题)

    • 要么使用Slow Cheetah(简单),要么修改silverlight项目的csproj xml(有点痛苦,但一旦完成一次也不错 - 这里是link允许您为ServiceReferences.ClientConfig文件进行配置特定的转换) . 使用慢速猎豹,您可以通过右键单击特定于配置的变换来查看变换 . 我和Kit的改造工作都是如此 .

    • 将xml(取自上面的链接)添加到silverlight项目(csproj)文件中 . 它类似于Kit 's but not sure why his wouldn' t编译,这个(这是我的第二个问题) - 下面的xml

    • 重建项目,然后发布 . .xap将在其中包含已转换的ServiceReferences.ClientConfig文件 .

    • 如果您想与整个团队共享部署配置,请将MyProject.Publish.Xml添加到您的存储库

    <UsingTask TaskName =“TransformXml”AssemblyFile =“$(MSBuildExtensionsPath32)\ Microsoft \ VisualStudio \ v10.0 \ Web \ Microsoft.Web.Publishing.Tasks.dll”/>
    <Target Name =“BeforeBuild”Condition =“Exists('ServiceReferences . $(Configuration).ClientConfig')”>
    <Move SourceFiles =“ServiceReferences.ClientConfig”DestinationFiles =“ServiceReferences.Build.ClientConfig”/>
    <TransformXml Source =“ServiceReferences.Build.ClientConfig”Destination =“ServiceReferences.ClientConfig”Transform =“ServiceReferences . $(Configuration).ClientConfig”/>
    </目标>
    <Target Name =“AfterBuild”Condition =“Exists('ServiceReferences.Build.ClientConfig')”>

    <Delete Files =“ServiceReferences.ClientConfig”/> <移动SourceFiles =“ServiceReferences.Build.ClientConfig”DestinationFiles =“ServiceReferences.ClientConfig”/> </目标>

相关问题