views:

148

answers:

3

I'm frequently adding a lot of content files (mostly images and js) to my ASP.NET project. I'm using VS publish system, and on publish, new files are not published until I include them in the project. I would like to auto include all files in specified directory. Is there a way to specify wich directories should be auto-included in csproj file or anywhere else?

A: 

Hey,

If you use a web site project files would be automatically included.

In a web site application project they are not.

Are you tied to the wap project type?

rtpHarry
Unfortunately, this is not an option...
Marko
A: 

Not to my knowledge; however my suggestion is to paste them into the project as this will include them by default. So, instead of pasting them into the directory via Explorer, use Visual Studio to paste the files into the folders.

subkamran
+2  A: 

You simply can extend your website .csproj file. Just add your content root folder with a recursive wildcard:

...
<ItemGroup>
    <!-- your normal project content -->
    <Content Include="Default.aspx" />

    <!-- your static content you like to publish -->
    <Content Include="Images\**\*.*" />
</ItemGroup>
...

Doing so makes this folder and all content below visible inside your solution browser.

If you try to hide the folder inside the solution browser by specifying

<Content Include="Images\**.*.*">
    <Visible>false</Visible>
</Content>

it will not be published.


Update

As you already discovered the wildcard will be replaced as soon as you touch the folder inside your solution because VS projects are not designed to contain arbitrary content.

So you will have to make sure the folder and its contents are never modified from within VS - adding or removing files can only be done on the file system ... which is what you wanted as i understood your question.

It would be easier if the folder could be hidden in VS but i couldn't find a way to hide it AND publish.

Another unsuccessful approach was to include the folder by a CreateItem Task. This resulted in the contents of folder being published to \bin\app.publish\... and could not be convinced to publish it together with the content items inside the .csproj so i did not present it in my answer.

Filburt
It works until I add or remove file manually. After that line <Content Include="Images\**\*.*" /> disappears from project file.
Marko