使用虚拟应用程序托管azure Web角色会发送整个项目,但不会处理配置转换

5 publish azure webrole

这是一个相当漫长的问题,但它确实解释得很好.

我有一个Web角色,其根网站转发到该网站下的虚拟应用程序.我的项目在本地运行良好,几乎在云中完美运行.我正在使用新的构建配置来使我的站点的web.config在Azure上工作(因为我需要使用sql会话状态).

无论如何,在检查我的托管网站后,我可以分别在文件夹0,1,2中看到3个网站.0代表我的root,该文件夹的内容是托管应用程序的最小内容,只有我的bin,default.aspx,packages和web.config.这非常有用,我可以通过关注数据库中的会话来看到它的工作原理.

但是,当检查代表虚拟应用程序的其他(相同)文件夹时,我可以看到整个可视工作室项目.代码文件,web.config转换等.此外,转换实际上没有被处理.整个项目只是在那里倾倒.

我使用Visual Studio 2010将我的应用程序发布到我的Web角色.我在那里的设置中看不到任何明显的东西来控制这种行为.如果它有帮助,这是我的服务定义文件的一部分.

<WebRole name="root" vmsize="Small">
    <Sites>
      <Site name="Web">
        <VirtualApplication name="en" physicalDirectory="../../../sitefolder" />
        <VirtualApplication name="en-gb" physicalDirectory="../../../sitefolder" />
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    </Endpoints>
    <Imports>
      <Import moduleName="Diagnostics" />
      <Import moduleName="RemoteAccess" />
    </Imports>
  </WebRole>
<WorkerRole name="emailer" vmsize="ExtraSmall">
    <Imports>
      <Import moduleName="Diagnostics" />
      <Import moduleName="RemoteAccess" />
      <Import moduleName="RemoteForwarder" />
    </Imports>
</WorkerRole>
Run Code Online (Sandbox Code Playgroud)

那里也有配置设置,但我省略了它们.非常感谢您在此提供的任何帮助.

编辑1这里是我的解决方案中的windows azure项目的项目文件,在此处详细说明的更改实施后:http: //michaelcollier.wordpress.com/2013/01/14/multiple-sites-in-a-web-role /

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
*** entire content as normal and untouched manually ***
<!-- Import the target files for this project template -->
  <PropertyGroup>
    <VisualStudioVersion Condition=" '$(VisualStudioVersion)' == '' ">10.0</VisualStudioVersion>
    <CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.0\</CloudExtensionsDir>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Staging01' ">
    <OutputPath>bin\Staging01\</OutputPath>
  </PropertyGroup>
  <PropertyGroup>
    <!-- Inject the publication of "secondary" sites into the Windows Azure build/project packaging process. -->
    <CoreBuildDependsOn>
      CleanSecondarySites;
      PublishSecondarySites;
      $(CoreBuildDependsOn)
    </CoreBuildDependsOn>
    <!-- This is the directory within the web application project directory to which the project will be "published" for later packaging by the Azure project. -->
    <SecondarySitePublishDir>azure.publish\</SecondarySitePublishDir>
  </PropertyGroup>
  <!-- These SecondarySite items represent the collection of sites (other than the web application associated with the role) that need special packaging. -->
  <ItemGroup>
    <SecondarySite Include="..\bobblejob.com\bobblejob.com.csproj" />
  </ItemGroup>
  <Target Name="CleanSecondarySites">
    <RemoveDir Directories="%(SecondarySite.RootDir)%(Directory)$(SecondarySitePublishDir)" />
  </Target>
  <Target Name="PublishSecondarySites" Condition="'$(PackageForComputeEmulator)' == 'true' Or '$(IsExecutingPublishTarget)' == 'true' ">
    <MSBuild Projects="%(SecondarySite.Identity)" Targets="Build;_WPPCopyWebApplication" Properties="Configuration=$(Configuration);Platform=$(Platform);WebProjectOutputDir=$(SecondarySitePublishDir)" />
  </Target>
  <Import Project="$(CloudExtensionsDir)Microsoft.WindowsAzure.targets" />
</Project>
Run Code Online (Sandbox Code Playgroud)

为了进行编译,我必须在我的bobblejob.com文件夹中手动创建一个文件夹"azure.publish".可能错误是你所说的构建应该只在IsExecutingPublishTarget为真时运行吗?我希望这能在我的开发盒上运行,以及我设置的任何和所有部署......

- 2013年9月11日 - 这仍然是一个问题.有没有人有解决方案?

mco*_*ier 5

我认为你遇到的问题非常类似于我今年早些时候发表的博客情况.见http://michaelcollier.wordpress.com/2013/01/14/multiple-sites-in-a-web-role/

基本上,当Visual Studio打包您的Web角色时,它不会"知道"physicalDirectory属性指定的文件是Web项目,因此不执行任何正常的构建操作(编译,配置转换等)

我的博客文章描述了一种解决方法,通过在构建过程中注入一些自定义操作.希望能帮助到你!