【问题标题】:Adding additional content folders to Azure package将其他内容文件夹添加到 Azure 包
【发布时间】:2015-01-15 04:35:15
【问题描述】:

我正在使用 Azure SDK 2.5 我在云服务项目中担任 Web 角色。我想以某种方式添加一个文件夹,以便将其部署在 approot 的父目录中。我还没有找到一种方法来做到这一点,这让我想知道在 csdef 中定义虚拟目录的能力有什么用。

所以我想我会尝试通过 csdef 中的 Contents/Content xml 配置添加文件夹。我要么从根本上误解了这部分配置的作用,要么完全被破坏了。

假设这个文件夹结构

  /
    /CloudService
    /SomeOtherContent

如果我定义以下内容:

<Contents>
      <Content destination="frontend">
        <SourceDirectory path="..\SomeOtherContent" />
      </Content>
    </Contents>

我得到了构建:

错误 CloudServices089:找不到源目录 'C:\src\template\src\Template.CloudService\bin\Debug\..\SomeOtherContent'

好的,它启动了 bin\Debug,所以我就让它 ..\..\..\SomeOtherContent

错误 CloudServices089:找不到源目录 'C:\src\template\src\Template.CloudService\..\..\..\SomeOtherContent'

是的没错,我的相对路径解析的文件夹已经改变了!!!它不再是 bin\Debug。哇!?如何使它起作用?如果我输入完整驱动器限定的绝对路径,它就可以工作。

【问题讨论】:

    标签: azure azure-sdk-.net cspack


    【解决方案1】:

    所以我通过让 MSBuild 解析路径并将其推送到我称为 FrontendDir 的环境变量来解决这个问题。

    <Contents>
          <Content destination="frontend">
            <SourceDirectory path="%FrontendDir%" />
          </Content>
        </Contents>
    

    并在我添加的 ccproj 中:

    <UsingTask
        TaskName="SetEnvironmentVariableTask"
        TaskFactory="CodeTaskFactory"
        AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll">
    
        <ParameterGroup>
          <Name ParameterType="System.String" Required="true" />
          <Value ParameterType="System.String" Required="true" />
        </ParameterGroup>
    
        <Task>
          <Using Namespace="System" />
          <Code Type="Fragment" Language="cs">
            <![CDATA[
              Environment.SetEnvironmentVariable(Name, Value);
            ]]>
          </Code>
        </Task>
      </UsingTask>
      <Target Name="BeforeBuild" Condition=" '$(FrontendDir)' == '' ">
        <Message Text="Setting Project Dir" Importance="high" />
        <SetEnvironmentVariableTask Name="FrontendDir" Value="$(ProjectDir)\..\Template.FrontEnd\dist" />
      </Target>
    

    最好将整个路径放入 env var 中,因为您可以在不同的构建场景中通过覆盖值轻松覆盖它(例如 /p:FrontendDir="c:\foo")

    所以这很有效,而且效果很好。我仍然说我之前看到的相对路径分辨率更改文件夹的行为是......坏了。它只是不适用于任何可用的相对路径。

    【讨论】:

    • 如果你能去乔治亚州,我欠你一杯啤酒……和一个拥抱!谢谢,这很有帮助
    • 哈哈太棒了。必须检查您的个人资料以确保您不是在前苏联格鲁吉亚 ?
    【解决方案2】:

    您会看到相同的错误,但来自不同的 msbuild 目标。

    第一个错误(使用..\..\ 时)在PreValidateServiceModel 处引发,它传入源位置并检查路径

    ServiceDefinitionFile="@(SourceServiceDefinition)"
    ServiceConfigurationFile="@(SourceServiceConfiguration)"
    

    C:\src\Azure\ServiceDefinition.csdef:错误 CloudServices089:不能 在角色中找到源目录 'C:\src\Azure\..\..\Installers\' 网络主机。 [C:\src\Azure\Azure.ccproj]

    在项目“Azure.ccproj”中完成构建目标“PreValidateServiceModel” -- 失败。

    在目标位置传递的ValidateServiceFiles 引发第二个错误

    ServiceDefinitionFile="@(TargetServiceDefinition)"
    ServiceConfigurationFile="@(TargetServiceConfiguration)">
    

    C:\src\Azure\bin\Release\ServiceDefinition.csdef:错误 CloudServices089:不能 找到源目录 'C:\src\Azure\bin\Release\Installers\' 在角色 WebHost。 [C:\src\Azure\Azure.ccproj]

    在项目“Azure.ccproj”中完成构建目标“ValidateServiceFiles”——失败。

    如果您反映 C:\Program Files\Microsoft SDKs\Azure.NET SDK\v2.9\bin\ServiceDescription.dll,您可以看到 ProcessRoleContents 方法正在执行验证,但使用SourceFile 来解析位置。

    一种选择是在构建开始之前确保目标文件夹存在(即使是空的)。

    如果 PreValidation 解决了路径,并且当保存 Target 时,它具有完整路径会更好。

    我最终编辑了 ccproj,并添加了这个

    <Target Name="BeforeAddRoleContent">
        <ItemGroup>
          <AzureRoleContent Include="Installers\">
            <RoleName>Azure</RoleName>
            <Destination></Destination>
          </AzureRoleContent>
        </ItemGroup>
    </Target>
    

    Referencing runtime content from .ccproj (Azure SDK 2.9)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 1970-01-01
      • 2013-09-02
      相关资源
      最近更新 更多