Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create folder inside debug or release con console application

i have a console application in vs2010 (C#) and in the project, i have a Folder added by me (right click on project.. add->folder) and i want that when i compile the application (debug or release), then the folder will be created (if not exists) in the debug or release directory.

Is that possible?

The console application is a daemon that access to a database and send emails with templates allocated in that folder.

I hope you can help me. Thanks!

like image 532
Phoenix_uy Avatar asked Dec 03 '25 19:12

Phoenix_uy


1 Answers

There's no "automatic" way to get VS to create folders (other than the specified output folder) during a build, but there's two pretty easys ways to accomplish it.

  • Use a post-build event, which you set up in the Build Events tab of your project's properties. This is basically a batch file that you run after the build completes, something like this:

    IF NOT EXIST $(OutDir)MySubFolder MKDIR $(OutDir)MySubFolder
    XCOPY /D $(ProjectDir)MySubFolder\*.tmpl $(OutDir)MySubFolder
    
  • Use MSBuild's AfterBuild event. This is my preferred method, mostly because it integrates better with our automated build process, but it's a little more involved:

    1. Right-click on your project node and Unload it
    2. Right-click on the unloaded project node and Edit the file
    3. Near the bottom is a commented-out pair of XML nodes. Uncomment the AfterBuild target and replace it with something like this:

      <Target Name="AfterBuild">
          <MakeDir Directory="$(OutDir)MySubFolder" Condition="!Exists('$(OutDir)MySubFolder')" />
      
          <CreateItem Include="$(ProjectDir)MySubFolder\*.tmpl">
            <Output TaskParameter="Include" ItemName="Templates" />
          </CreateItem>    
      
          <Copy SourceFiles="@Templates" DestinationFolder="$(OutDir)MySubFolder" ContinueOnError="True" />
      </Target>
      
    4. Save the changes, close the .csproj file, then right-click and Reload the project.

like image 153
Michael Edenfield Avatar answered Dec 06 '25 11:12

Michael Edenfield



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!