0

My question is somewhat similar to an already existing one: How to include other files to the output directory in C# upon build?

In my case though I'm not trying to include files of the mainproject into the output folder, but of another project in the same application (thus 2 projects A being the mainproject and B being the other one).

What I want is that whenever I compile the application A is giving the .exe while some files (.xml) in the B project are put into a folder in the output alongside the .exe from A.

Now I've tried the method from the similar question with changing the output type of the files in B. It works fine when I compile B (they land in the appropriate folder there). But when I compile the project as a whole (as A is the "main"), I run into the problem that the .dll (or whatever I decide to compile B as) is created BUT the folder and files from B are not existent.

Thomas
  • 2,886
  • 3
  • 34
  • 78
  • 1
    Did you try with [Custom Build Events](https://learn.microsoft.com/en-us/visualstudio/ide/specifying-custom-build-events-in-visual-studio?view=vs-2019)? – Steve Jan 20 '20 at 14:30
  • @Steve no. Did not use them before in any variation. Currently reading through your link. – Thomas Jan 20 '20 at 14:39
  • So do you need project b building before project a (does project b put the files project a needs in the requisite folder) ? – auburg Jan 20 '20 at 14:48
  • @auburg in essence whenever I compile the application (thus A) I need those files from B in the final output folder (everything else would mean I need to do manual steps which tends to produce errrors over short or long term) – Thomas Jan 20 '20 at 14:51
  • So a Post-Build event containing a batch files that copies from B to A seems enough – Steve Jan 20 '20 at 14:54
  • So i guess you need to do two things: make project b a dependency of project a (so when you build project a, project b is built first) and you need a postbuild step as @Steve suggested for project b that copies the files to the output folder – auburg Jan 20 '20 at 14:55
  • See https://stackoverflow.com/questions/10827024/copying-visual-studio-project-files-to-output-directory-during-build regarding copying files to the output folder – auburg Jan 20 '20 at 14:58
  • @auburg so in my case if I copy the whole folder it would be: xcopy "$(ProjectDir)TrSpec" "$(SolutionDir)$(OutDir)" /Y /I /E ? (when compiling for debug it does not copy into the debug folder) – Thomas Jan 20 '20 at 15:04
  • If you mean you've got xml files in the TrSpec folder then you need "$(ProjectDir)TrSpec\*.xml". Have a look at the build output window in vs where you'll see further output if it's not working for you. – auburg Jan 20 '20 at 15:12
  • @auburg tnx got it now in the post build event of B: xcopy "$(ProjectDir)TrSpec" "$(SolutionDir)\SBTestTool\bin\$(ConfigurationName)\TrSpec" /Y /I /E and works :) – Thomas Jan 20 '20 at 15:13
  • Also if these xml files are part of your solution in project b, you can select them in solution explorer and set the build output for them there (see the 2nd answer in the SO link i sent) – auburg Jan 20 '20 at 15:13
  • @auburg build output did only make them available in the project b but not in the solution destination. only by adding the post build event in addition did I manage to get it to work (tnx btw) – Thomas Jan 21 '20 at 08:35

0 Answers0