5

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?

2 Answers2

5

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!

mcollier
  • 3,721
  • 15
  • 12
  • Thanks for your answer and yes your link does answer the question I'm asking exactly. However I'm having trouble getting it to work. My first attempt was with the Alternate Method (since I'm not entirely comfortable editing the project file manually) however when I ran the project on my machine it completely hung the entire machine. After 20 minutes of trying to get control I ended up hard-resetting the thing! I will keep trying though and let you know how it goes... –  Sep 06 '13 at 11:33
  • Right, I have failed to get this working using both the methods in your blog post. However I admit I have never used MSBuild or any build configuration options before so it is quite possible I have made a mistake. First off I tried the alternate method on your page. One of the commands in the Post-Build section appears to be to run MSBuild again - hence my computer went nuts while running it as each time it ran it spawned another one. I can't see how this is correct in your post. I then tried your first method and have done each step carefully. I shall explain more in my question above. –  Sep 06 '13 at 12:53
  • Found a possible cause of a problem with your scripts: $(ProjectDir)..\bobblejob-azure\Sites\$(ProjectName) turns into C:\Chaotic\Projects\bobblejob.com\bobblejob.com\..\bobblejob-azure\Sites\bobblejob.com - i.e. your ".." is not going backwards a directory. –  Sep 06 '13 at 14:14
  • Interesting . . . thanks for the info . . . I'll have to look into that. – mcollier Sep 07 '13 at 02:54
  • I think the difference between what I'm doing and what you've got there is that you are hosting multiple sites, but my situation is a site with multiple virtual applications beneath it. I am afraid I still can't seem to get this to work. Thank you for the response though, I have marked it as useful. –  Sep 09 '13 at 09:30
0

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. ;-)