views:

453

answers:

2

I have a solution which contains a website and various class libraries. The exists on the file system like so:

C:\Projects \MyWebsite\dev\MyWebsite.sln  
C:\Projects\Core\MyClassLibrary1.csproj  
C:\Projects\Core\MyClassLibrary2.csproj

I want to move the App.config file from MyClassLibrary1 project to the bin of the MyClassLibrary2. I want to do this on post build in VS or MSBuild using relative paths if possible. This way anybody checking out the projects will not have to modify any paths if they choose to locate the project in a different location.

I have already tried the following approaches but to no avail.

copy /Y "$(ProjectDir)App.config"  
$(ProjectDir)\..\ MyClassLibrary2\$(OutDir)\ MyClassLibrary2.dll.config"

Any ideas?

Thanks

+2  A: 

Consider adding the App.config file in your second class library using Visual Studio Add As Link.

Add -> Existing Item -> Add As Link

The Add As Link command is shown if you click the dropdown next to regular Add button in Visual Studio. This way you can reuse the file in multiple projects.

João Angelo
+1 better option
Maxwell Troy Milton King
Thanks, but as you can see in my example I need to rename the file when I copy it across so that MyClassLibrary2 can pick it up. Not sure if linking will do a rename. Hence my current approach.
Cragly
Visual Studio will rename App.config for each project at build time. The linked file is resolved before building so you'll get the expected output. Try it for yourself, it only takes a few seconds.
João Angelo
Worked like a charm! thanks for that. Never expected VS to do the renaming.
Cragly
A: 

Try some other common MSBuild properties, although João has a better suggestion I think.

Maxwell Troy Milton King