azure - 将其他内容文件夹添加到 Azure 包

标签 azure azure-sdk-.net cspack

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

所以我想我应该尝试通过 csdef 中的 Contents/Content xml 配置添加文件夹。我要么从根本上误解了这个配置的作用,要么它彻底被破坏了。

假设这个文件夹结构

  /
    /CloudService
    /SomeOtherContent

如果我定义以下内容:

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

并构建我得到:

error CloudServices089: Cannot find the source directory 'C:\src\template\src\Template.CloudService\bin\Debug\..\SomeOtherContent'

好吧,它启动了 bin\Debug,所以我将其设置为 ..\..\..\SomeOtherContent

error CloudServices089: Cannot find the source directory 'C:\src\template\src\Template.CloudService\..\..\..\SomeOtherContent'

是的,没错,解析我的相对路径的文件夹已更改!它不再是 bin\Debug。卧槽!?如何才能使其发挥作用?如果我输入完整驱动器限定的绝对路径,它就会起作用。

最佳答案

因此,我通过让 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>

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

所以这很有效,而且效果相当好。我仍然说我之前看到的相对路径分辨率更改文件夹的行为已经被破坏了。它只是不能以任何可用的方式处理相对路径。

关于azure - 将其他内容文件夹添加到 Azure 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27956869/

相关文章:

c# - Azure 搜索 v11 : Indexing nullable Collection of Complex Type

.net - 如何使用 Azure DevOps CI/CD 部署多个 Azure Functions

c# - Azure Functions Newtonsoft.Json 加载错误

powershell - Azure 存储 - 生成 SAS token (门户与 PowerShell

visual-studio-2012 - Azure 2.5 SDK 升级导致 CSPack 失败

java - Windows Azure cspack.exe 是开源的吗?

azure - 为什么 mywebsite.dll.config 没有包含在我的 cspkg 中?

azure - 在现有 aks 上启用 rbac 和 aad

c# - 如何使用 Fluent 资源管理器 SDK 获取部署的输出资源?

azure - 从 Azure Function 调用 Azure SQL 数据库时出现暂时性错误