1

我使用 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。哇!?如何使它起作用?如果我输入一个完整的驱动器限定的绝对路径,它就可以工作。

4

2 回答 2

0

所以我通过让 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")

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

于 2015-01-15T06:10:15.653 回答
0

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

第一个错误(使用时..\..\)被抛出,PreValidateServiceModel在源位置传递并检查路径

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

C:\src\Azure\ServiceDefinition.csdef : 错误 CloudServices089: 在角色 WebHost 中找不到源目录 '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: 在角色 WebHost 中找不到源目录 'C:\src\Azure\bin\Release\Installers\'。[C:\src\Azure\Azure.ccproj]

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

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

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

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

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

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

从 .ccproj (Azure SDK 2.9) 引用运行时内容

于 2019-05-23T22:57:48.050 回答