我正在使用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 \模板\ SRC \ Template.CloudService \ BIN \调试\ .. \ SomeOtherContent'
好的,所以它启动bin \ Debug,所以我只是让它.. \ .. \ .. \ SomeOtherContent
错误CloudServices089:找不到源目录 'C:\ SRC \模板\ SRC \ Template.CloudService \ .. \ .. \ .. \ SomeOtherContent'
是的,没错,解析我的相对路径的文件夹已经改变了!它不再是bin \ Debug。 WTF!?怎么能这样做?如果我输入一个完整的驱动器合格绝对路径,它就可以工作。
答案 0 :(得分: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”)
这样可以很好地工作和运作。我仍然说我之前看到的相对路径分辨率改变文件夹的行为是......破碎的。它只是不能以任何可用的方式使用相对路径。
答案 1 :(得分:0)
您看到的是相同的错误,但是来自不同的msbuild目标。
第一个错误(使用..\..\
时)被抛出到PreValidateServiceModel
,该错误通过Source位置并检查路径
ServiceDefinitionFile="@(SourceServiceDefinition)"
ServiceConfigurationFile="@(SourceServiceConfiguration)"
C:\ src \ Azure \ ServiceDefinition.csdef:错误CloudServices089:无法 在角色中找到源目录“ C:\ src \ Azure \ .. \ .. \ Installers \” WebHost。 [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解析路径并且保存目标时,它具有完整路径会更好。
我最终编辑了ccproj,并添加了它
<Target Name="BeforeAddRoleContent">
<ItemGroup>
<AzureRoleContent Include="Installers\">
<RoleName>Azure</RoleName>
<Destination></Destination>
</AzureRoleContent>
</ItemGroup>
</Target>