Deploy Files In Azure Worker Role

I have a worker role that uses the MAF framework. That means I need to add assemblies that my project do not reference directly, and these files need to be in a specific folder structure(http://msdn.microsoft.com/en-us/library/bb384201.aspx). I had the same scenario with a web role and was able to achieve this because when you package a web role, it can copy every file found in the project folder. So I had a BeforeBuild event that would copy all the files to my bin folder for my web app, and all the files in there were packaged in my azure package.

The same thing does not apply to worker roles. Before the build I create the folder structure in the bin\config folder, I can see the structure there, but the files do not get copied in the azure package at the end. I know the usual way to achieve this is to add a reference to those dll and set them to copy local, but that won't place the files in the required folder structure.

Another way around would be to add custom code that would load those files from azure storage, and copy them when the role is starting, but that means I need to make extra steps everytime I deploy, and make sure that the storage is updated at the same time of my package. I was wonedring if there was any other way to achieve this. I cannot believe that this is completely unsupported. I did not create a custom framework for my add-ins, I am usign the one provided by Microsoft with the .NET framework, so I really hope there is a way to add those files to the azure package.

Thanks, Louis

April 18th, 2012 6:17pm

Here is what I dened up doing to achieve this:

Make a copy of the Microsoft.WindowsAzure.targets file found in the MSBuild folder to your Azure project folder. (C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Windows Azure Tools\1.6 was the folder for me)

Modify the filed you just copied to comment a part that would delete any "oprhan" file that does not belong to the role it is building. Without removing this, the file will get deleted automatically because it will detect that the project does not need it.
<ItemGroup>
      <OrphanedWorkerFiles Include="$(IntermediateWorkerOutputPath)**\*.*" Exclude="@(WorkerFiles->'$(IntermediateWorkerOutputPath)%(TargetPath)')" />
    </ItemGroup>
    <Delete Files="@(OrphanedWorkerFiles)" ContinueOnError="true" />
That can be found on line 2864 with version 1.6 of the Azure SDK. Comment it out or remove it.

Modify the ccproj file of your Azure project to point to that file instead fo the original one. The import should now look like this: <Import Project="$(ProjectDir)Microsoft.WindowsAzure.targets" />

You can then add a <Target Name="BeforeBuild"></Target> node in that ccproj file, or add before build events in that project that will copy the required file to this folder: $(ProjectDir)obj\$(ConfigurationName)\[Azure role], and replace [Azure role] by the name of the role you want to copy these files to.

Once you've done that, you can rebuild your solution, and any files copied during your before build event will be included in your final azure package.

Cheers!

  • Marked as answer by LouisPhil Wednesday, April 18, 2012 8:57 PM
Free Windows Admin Tool Kit Click here and download it now
April 18th, 2012 8:56pm

Here is what I dened up doing to achieve this:

Make a copy of the Microsoft.WindowsAzure.targets file found in the MSBuild folder to your Azure project folder. (C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Windows Azure Tools\1.6 was the folder for me)

Modify the filed you just copied to comment a part that would delete any "oprhan" file that does not belong to the role it is building. Without removing this, the file will get deleted automatically because it will detect that the project does not need it.
<ItemGroup>
      <OrphanedWorkerFiles Include="$(IntermediateWorkerOutputPath)**\*.*" Exclude="@(WorkerFiles->'$(IntermediateWorkerOutputPath)%(TargetPath)')" />
    </ItemGroup>
    <Delete Files="@(OrphanedWorkerFiles)" ContinueOnError="true" />
That can be found on line 2864 with version 1.6 of the Azure SDK. Comment it out or remove it.

Modify the ccproj file of your Azure project to point to that file instead fo the original one. The import should now look like this: <Import Project="$(ProjectDir)Microsoft.WindowsAzure.targets" />

You can then add a <Target Name="BeforeBuild"></Target> node in that ccproj file, or add before build events in that project that will copy the required file to this folder: $(ProjectDir)obj\$(ConfigurationName)\[Azure role], and replace [Azure role] by the name of the role you want to copy these files to.

Once you've done that, you can rebuild your solution, and any files copied during your before build event will be included in your final azure package.

Cheers!

  • Marked as answer by LouisPhil Wednesday, April 18, 2012 8:57 PM
April 18th, 2012 8:56pm

One little tweak to this method:  instead of copying the entire .targets file (and potentially missing out on upgraded functionality in future versions), I chose to simply copy the CopyWorkRoleFiles target into my .ccproj file just after the Microsoft.Windows.Azure.targets import.

Thanks!

Free Windows Admin Tool Kit Click here and download it now
May 1st, 2014 7:59pm

Hi Burton,Louis .

Need help.

Currently i am using a .proj file that i pass to msbuild.exe  for creating the azure packages(.cspkg). Even i am fiddling with updating the worker role to include extra files that are not part of the project . 

The .proj file will build the entire solution , and the .csproj for the azure has an import attribute to import the WindowsAzure.target. 

So if i need to add the above line of code should i add then to the csproj or the .proj ?

March 24th, 2015 2:55pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics