【问题标题】:ServiceReferences.ClientConfig plus slow cheetah not transformingServiceReferences.ClientConfig 加上缓慢的猎豹不转换
【发布时间】:2012-08-12 06:28:47
【问题描述】:

我在 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 project\bin 文件夹并解压缩我的 xap 文件,它最终会包含所有 ClientConfig 文件,并且主配置文件保持不变。我的 xap 文件中也有一个错误,在“xdt:Transform”下划线显示“未声明 'http://schemas.microsoft.com/XML-Document-Transform:Transform' 属性。”

如果我右键单击 ServiceReferences.MyConfig.ClientConfig,Preview Transform 它会准确地向我显示它应该做什么(具有更新 IP 地址的相同服务)。另一个疯狂的事情是,这以前是有效的,我不知道我做了什么来破坏它(在我去提交回购之前就坏了)。我已经卸载并重新安装了慢猎豹,重新启动等。

有人知道如何修复此转换以使其正常工作吗?

【问题讨论】:

标签: .net visual-studio silverlight slowcheetah


【解决方案1】:

如果您真正想做的只是替换地址,那么您可能会尝试这样的事情(注意,我没有使用 SlowCheetah 本身,但也许这种间接方法会给您足够的洞察力来解决问题)。我正在使用内置的转换机制并连接到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 中的路径
  • 确保两个项目的依赖关系和构建顺序正确

【讨论】:

  • 套件,感谢您的回答。我发誓我尝试在其中添加定位器几次,但没有成功。我将其粘贴进去,更改了一些内容,现在 .xap 在 silverlight 项目中具有正确的配置文件,但是当我发布 Web 项目时,ClientBin 文件夹中包含的 .xap 文件具有未转换的配置跨度>
  • 从头开始。当我再次清理和重建时,即使 silverlight 项目 .xap 不再包含转换后的配置 - 我又回到了原来的问题。当您在项目中执行此转换时,您是否看到它转移到 ..\yourWebProj\ClientBin\YourSLProj.xap?
  • 我更新了我的答案,希望它能让你更接近。我实际上并没有使用 SlowCheetah,但也许这里有足够的细节可以帮助您找到解决方案。如果您确定,请随时添加到答案中。
  • Kit,什么是ServiceReferences.Template.ClientConfig?它是您制作的自定义模板吗?
  • @Mario - 是的。基本上想要有一个模板和 ServiceReferences.*Env*.config 文件进行版本控制,但不是 ServiceReferences.ClientConfig,因为它是生成的。
【解决方案2】:

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

  1. 确保 Web 项目属性构建输出路径为 \bin\,并且在项目属性的 Silverlight 应用程序部分中将配置特定文件夹设置为否
  2. 确保 Silverlight 项目属性构建输出路径为 \bin\(这是我的第一个问题)
  3. 要么使用 Slow Cheetah(简单),要么修改 silverlight 项目的 csproj xml(有点痛苦,但一次完成后还不错 - 这里是 link 允许您为 ServiceReferences.ClientConfig 进行配置特定的转换文件)。使用慢速猎豹,您可以通过右键单击配置特定的转换来查看您的转换。我和 Kit 的转换工作。
  4. 将 xml(取自上述链接)添加到 silverlight 项目 (csproj) 文件中。它类似于 Kit 的,但不知道为什么他不会编译,而这个会(这是我的第二个问题)- xml 下面
  5. 重建项目,然后发布。 .xap 将包含转换后的 ServiceReferences.ClientConfig 文件。
  6. 如果您想与整个团队共享您的部署配置,请将 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>
 <Target Name="AfterBuild" Condition="Exists('ServiceReferences.Build.ClientConfig')">
     <Delete Files="ServiceReferences.ClientConfig" />
    <Move SourceFiles="ServiceReferences.Build.ClientConfig" DestinationFiles="ServiceReferences.ClientConfig" />
 </Target>

【讨论】:

    猜你喜欢
    • 2013-12-31
    • 2012-08-22
    • 1970-01-01
    • 2017-11-18
    • 2014-02-03
    • 2016-10-07
    • 1970-01-01
    • 2016-08-19
    • 2012-01-12
    相关资源
    最近更新 更多