Spikeh
Spikeh

Reputation: 3695

Visual Studio: Pre-Build add contents of directory to project

I have the following setup:

I've written a business layer that allows users in the admin panel to upload images, which are then physically saved to the CDN path that's configured (currently on the local machine i.e. C:\Code\SolutionName\CDNProject\images). The main website then uses the same business layer to find and distribute the images via http://cdn.domain.com/images/. http://cdn.domain.com is currently set to http://localhost:55555, while we develop.

Whenever an image is created via the admin panel, it is physically created on disk. Each developer works on his own machine, we we want to be able to check these files in to TFS, for the time being. As you might have guessed, adding files to the file system does not automatically reference them in the project:

Broken references

I thought there may be some way to reference these images as resources, or set a directory to a "content" directory of sorts... but I can't find anything.

Some developers work remotely via VPN, and do not have access to the local network (only TFS), so a network path is not an acceptable solution.

I thought I might be able to set a pre-build event up, to add all files in a directory to the project?

Upvotes: 0

Views: 1542

Answers (2)

Alexandru C.
Alexandru C.

Reputation: 3395

Visual Studio project files have an XML syntax. Project file properties can be modified in a simple text editor (files added/removed, etc.).

You can create a script to open your solution, and before actually opening the solution, you can scan that directory and "inject" the files (with the appropriate XML tags) in the project files.

I don't think you can add this as a pre-build event because the project files are already loaded at that point, and you cannot modify them while they're used.

Upvotes: 0

Dmitry Pavlov
Dmitry Pavlov

Reputation: 28290

There is no very easy way to do that. There are a few ways to think about:

1) Write VS adding which adds new files to project (via DTE - starting point). Find out how to automatically run this VS addin on Pre-Build step. Install this addin to your developers machines.

2) Extend your admin logic to automatically check-in the uploaded files to TFS via TFS API

3) try to apply more sofisticated techonologies like this one: T4 Tutorial: Integrating Generated Files in Visual Studio Projects

Hope that helps,

Upvotes: 1

Related Questions