views:

2075

answers:

5

I have a VS2008 I want to copy certain files from a directory into my /bin/ folder. I have set the files (located in /common/browserhawk/) to "Copy to Output Directory". However, it copies the folder structure as well: the files are copied to /bin/common/browserhawk/

How do I get these files to copy to just /bin/? I do not want to store these in the root of the website to get them to copy correctly.

Related Question: http://stackoverflow.com/questions/1013419/visual-studio-adds-dll-and-pdb-to-project-after-compiling/1013561

+1  A: 

You could build a batch file to copy the files and execute it as a post-build event.

jvanderh
I ended up doing this for one of my projects (although I used a Python script rather than a bat).
Fire Lancer
+1  A: 

Add the following to your .csproj/.vbproj file

<Target Name="AfterBuild">
    <Copy
        DestinationFolder="$(OutputPath)"
        SourceFiles="@(RootContent)"
        SkipUnchangedFiles="true"
        />  
</Target>

Then change the Build Action of any files you want in the root folder to RootContent.

Paul Alexander
Great! Can you access this through the VS 2008 dialogs?
bobobobo
Not through the dialogs...but you can edit your project in VS. Right-click the project and select Unload Project. Then right click and select Edit. Then you can edit the MSBuild file that is your project.
Paul Alexander
Thanks, this looks useful. Unfortuntely, even after adding your snippet to the .vbproj file, `RootContent` does not show up in the "Build Action" dropdown list and entering it manually results in a "Property value is not valid" error from Visual Studio. What did I miss?
Heinzi
Not working with Visual Studio 2010 C# Console Application project.
AMissico
Not working with Visual Studio 2010 VB.NET Console Application project.
AMissico
Not working with Visual Studio 2008 C# Console Application project.
AMissico
The actual Item list might be named something different. You can set the project build settings to Diagnostic and then build the project. In the output window, you'll see a long list of property/item values that MSBuild used to build the project. Check for the property value that best matches.
Paul Alexander
A: 

I ended up adding a step to the nant build file to copy after successful compliation

<target name="action.copy.browserhawk.config" depends="compile.source">
 <copy todir="${App.Web.dir}/bin/" includeemptydirs="false">
  <fileset basedir="${browserhawk.config.dir}">
   <include name="bhawk_bb.dat" />
   <include name="bhawk_sp.dat" />
   <include name="browserhawk.properties" />
   <include name="maindefs.bdd" />
   <include name="maindefs.bdf" />
   <include name="BH_PRO.lic" />
  </fileset>
 </copy>
 <echo message="COPY BROWSERHAWK CONFIG: SUCCESS   ${datetime::now()}" />
</target>
Steve Wright
-1; Because answer relies on *NAnt*.
AMissico
+3  A: 

You can add a Post Build Event to copy the files. Goto project properties, Build Events tab and add the following to the Post-build event command line:

copy "$(ProjectDir)\common\browserhawk*.*" "$(TargetDir)"

Be sure to include the quotes if your project path has spaces in it.

Bill A.
A: 

I believe the XCOPY command handles directories and files better. Therefore,

    XCOPY "$(ProjectDir)common/browserhawk" "$(TargetDir)" /E /I /F /Y

Which allows for creating folders off the target directory.

    XCOPY "$(ProjectDir)Templates" "$(TargetDir)" /E /I /F /Y

The Project folder/file structure of:

    A:\TEMP\CONSOLEAPPLICATION3\TEMPLATES
    ├───NewFolder1
    ├───NewFolder2
    │       TextFile1.txt
    │       TextFile2.txt
    └───NewFolder3
            TextFile1.txt
            TextFile2.txt
            TextFile3.txt

Becomes:

    A:\TEMP\CONSOLEAPPLICATION3\BIN\DEBUG
    │   ConsoleApplication3.exe
    │   ConsoleApplication3.pdb
    │   ConsoleApplication3.vshost.exe
    │   ConsoleApplication3.vshost.exe.manifest
    ├───NewFolder1
    ├───NewFolder2
    │       TextFile1.txt
    │       TextFile2.txt
    │
    └───NewFolder3
            TextFile1.txt
            TextFile2.txt
            TextFile3.txt
AMissico