Hosting azure web role with virtual application sends entire project and doesn't process configuration transforms

StackOverflow https://stackoverflow.com/questions/18638866

  •  27-06-2022
  •  | 
  •  

Question

This is a rather long winded question but it does explain it quite well.

I have a web role which has a root site that forwards to virtual applications beneath that site. My project works fine locally and almost works perfectly in the cloud. I am using a new build configuration to get my site's web.config to work on Azure (as I need to use sql session state).

Anyway, upon inspection of my hosted site I can see 3 sites in folders 0, 1, 2 respectively. 0 represents my root and the content of that folder is the minimal for the hosted application, just my bin, default.aspx, packages and web.config. This works great and I can see it working by keeping an eye on the sessions in my database.

However, when checking either of the other (identical) folders which represent the virtual applications I can see the ENTIRE visual studio project there as is. Code files, web.config transforms, etc. What's more, the transforms aren't actually processed. The entire project is just dumped up there.

I have used Visual Studio 2010 to publish my application to my web role. I cannot see anything obvious in the settings there to control this behaviour. Here is part of my service definition file if it helps.

<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>

There are also configuration settings in there but I have omitted them. Thank you very much for any and all help here.

EDIT 1 Here is my project file for the windows azure project in my solution after the changes detailed here were implemented: 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>

In order to make this compile I had to manually create a folder "azure.publish" in my bobblejob.com folder. Could the error be where you have said the build should only run when IsExecutingPublishTarget is true? I want this to run on my dev box and any and all deployments I have set up...

-- 11/09/13 - this is still an issue. Has anyone got a solution?

Was it helpful?

Solution

I think you're running into a problem very similar to a situation I blogged about earlier this year. See http://michaelcollier.wordpress.com/2013/01/14/multiple-sites-in-a-web-role/

Basically, when Visual Studio packages your web role, it doesn't "know" that the files specified by the physicalDirectory attribute are web projects, and thus doesn't perform any of the normal build operations (compile, config transforms, etc.)

My blog post describes a way to work around this by injecting some custom actions into the build process. Hope it helps!

OTHER TIPS

I finally have this working and it is thanks to the link above.

The first time I tried out this method it didn't work. I have since retried and it has worked - follow the link above. I suppose in between trying both methods I had read up on MSBuild so was able to read and understand what was going on.

The only other thing I did different was I named my temporary publish folder to "azure_publish" and not "azure.publish". I haven't read enough to know whether a period is a reserved character.

Thanks mcollier. Make sure you get a commission from Microsoft on this one. ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top