次の方法で共有


Windows Azure, MSBuild, and Lotsa Files!

So I’ve been working on a project, and I came across a little challenge that I thought folks may be interested in the solution to.

So, the problem is this, I have a dependency on a bunch of files that I need access to from my worker role in the cloud and dev fabric. I have all these files in a folder, and the folder has a sub-directory structure that I want preserve inside my project.

Question! How do I add this folder to my project, with the directory structure preserved, and have all the files “Copy To Output Directory” property set to something, like in my example,  “Copy Always”, so it gets taken up to the cloud with my package? Easy… well, kinda.

First step, from Windows Explorer, drag said folder into your role project:

image

This will add the folder into your project, with the folder structure in place, however the properties of the files will not be set, and therefore, when you publish your project, the files won’t be picked up in your package.

image

So, second step is, exclude the folder from your project. Don’t delete it! This will remove it from the disk, you just want to remove the reference of it from the csproj file.

image

Next, you need to unload your project.

image

Then edit the csproj file.

image

Inside the csproj, scroll down to the area where you find all the ItemGroup elements:

image

Add a new ItemGroup element, say above the app.config one (it doesn’t matter where), and set it to include your folder like so:

image

What you’re telling VS to do is, include the "Melbourne Photos” folder, recursively, to the project, with the CopyToOutputDirectory property set to Always.

When you reload the project:

image

You will notice all the files have been included in the project, and the Copy to Output Directory property has been set to Copy always for all of them!

image

When you publish your role, all these files will be taken up with your project, and accessible by your code!

Big thanks to Guy and Dan for helping with this!

Enjoy! :)

Comments

  • Anonymous
    November 08, 2009
    When do you stand on your left foot and rub your tummy?