Copy exe from one project to another's debug output directory - c#

I have two projects, ProjOne.exe and ProjTwo.exe. I want to build ProjOne.exe and it know that it's dependant on ProjTwo.exe so that it will copy ProjTwo.exe when it goes to build ProjOne.exe.
I also have a ProjThree.dll that it already does that for perfectly. But this in only because the dll is referenced by ProjOne.
Any way to do this like it does with DLLs/OCXs? Or is this going to be some POST build scripting? :) If so please give examples of the script I would use.
Thanks!

Go to Project ProjTwo Properties -> Build Events --> Post-build event command line :
echo f | xcopy /y "$(TargetPath)" "$(SolutionDir)ProjOne\bin\Debug$(TargetFileName)"
When you build ProjTwo, then it copies ProjTwo.exe to Debug folder of ProjOne

I ended up using ganchito55's method and it worked great. I then quickly realized that it would not suit my purposes when dealing with multiple files (such as debug files, etc). I also wanted to account for building in DEBUG and RELEASE.
I ended up doing the following...
1) Dig down to the project properties on ProjTwo:
Right click on project -> Properties -> Build Events
2) Add the following lines to the "Post-build event command line" box:
Copy ALL files used in the ProjTwo to the ProjOne output directory when building DEBUG output.
if $(ConfigurationName) == Debug xcopy /y "$(TargetDir)*.*" "$(SolutionDir)ProjOne\bin\Debug\"
Copy ALL files used in the ProjTwo to the ProjOne output directory when building RELEASE output.
if $(ConfigurationName) == Release xcopy /y "$(TargetDir)*.*" "$(SolutionDir)ProjOne\bin\Release\"

Related

How to change the path of exe file generated from console application in c#?

I have a console application and when I run it, an exe file is generated in Bin/Debug folder.
How can I change the path of exe generated to parent folder where src resides?
I created a c# console .Net Framework 4.8 project, there are two ways to achieve your needs.
The first way you can directly change the way the exe is generated in the properties, and the second way you can use the post-build method to copy the exe to src.
The first:
Modify in project->properties->build->output, for example, modify to ..
The Debug folder will be generated to the upper layer.
The second: copy only the exe.
xcopy /y /e "$(TargetPath)" "$(SolutionDir)"
Click on edit to view macros, or refer to documentation.
If you want to use it in .net.
xcopy /y /e "$(Targetdir)*.exe" "$(SolutionDir)"

Adding pre-build commands to copy files to a project in VS 2017

I have a folder which has a bunch of scripts in it. These are NOT in a project or solution.
What I need to do is using the pre-build event in VS, is copy these files using xcopy into the debug folder of a project.
I have worked out how to do this with stuff inside a solution or project. But trying to do it with external files is eluding me
Can anybody point me in the right direction please?
Projects have a Pre-build event that can be used for doing what you are looking to do.
You can find this in the Project Properties in the Build Events section.
Try the command as per:
c:\windows\system32\xcopy D:\source\*.* "$(TargetDir)" /s /e
For a list of the Build Parameters see MSDN: https://msdn.microsoft.com/en-us/library/42x5kfw4.aspx
The quotes around the $(TargetDir) are important if you have a space in any of your folder/file names

How to run executable from a different folder?

I'm using the following 2 lines in my post build event command line for my VS C# project.
start xcopy "$(TargetPath)" "$(ProjectDir)..\..\..\Bin\" /R /Y /F /I
start xcopy "$(TargetDir)$(TargetName).xml" "$(ProjectDir)..\..\..\Bin\" /R /
It basically copies whatever executables, dll's, etc... are created and copies them to another folder. I am doing this because the other folder contains resources which this project needs and is shared by other people.
Currently, when I run the project, it runs the .exe inside /bin/debug.. not the one that is copied out to other path. How can i change this?
I want the project to run the executable from the different folder not /bin/debug. Thank you for any help.
Select your startup project in Solution Explorer
Right click Properties
Select Debug tab
Select option Start external program and enter relative or full path to your copied executable
Alternatively, you can leave Start project option and configure Build->Output path to desired folder

Add Plugin DLL in MVC 4 Website after publish

I need to use external DLL not referenced in my main project. I've made some tests and it's working but now, I need to do it automatically.
So, in my "Post Build" event of my main web project, I put this :
Call c:\mybat.bat $(SolutionDir) $(TargetName) $(Configuration)
And in c:\mybat.bat, I've this :
set solution=%~1
set target=%~2
set configuration=%~3
set appli=Project1
rem : MSBuild...
cd "%solution%%appli%" && "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MsBuild.exe" "%solution%%appli%\%appli%.csproj" /p:Configuration=%configuration% /p:Platform="AnyCPU"
rem copy DLL generate by build
xcopy /Y /R "%solution%%appli%\bin\%appli%.dll" "%solution%%target%\bin\%appli%.dll*"
rem copy views...
xcopy /Y /R /S "%solution%%appli%\Views\*.*" "%solution%%target%\Views\"
And it's did the trick.
But, when I publish my website, the DLL 'Project1.dll' is not in my 'website\bin' folder. Only in my Bin project solution.
How can I add my *.dll and my view folder in the publish files ?
You have to include those files into your project, as publish copies only files which the msbuild process is aware of (i.e. which have been part of the project itself).
Another option might be to have the msbuild target file updated (by including custom/enhaned targets in your project file).
https://stackoverflow.com/a/1403360/2298807 contains a list of articles which might be used as a starting point for this.

Copy output of one project to output of other project

I have two C# projects. One is MainProject(exe) and other is ModuleProject (dll). What I want is that when I build my Moudule project, a copy of its output dll is copied to MainProject output folder. If I am building project in debug then it should go to debug folder.
I guess we can achieve this using build events, but I am not familiarized with them. Can anyone tell me exact command what should I write there, or any other solution.
use this link to learn about the post build:
use $(OutDir) to get to the output directory or $(TargetFileName) for the dll name. copy it using the copy command like in command line
it should be something like this:
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)lib\$(ProjectName).dll"
or something like:
copy /Y "$(TargetDir)$(ProjectName).dll" "d:\\MainProject\\bin\\debug\\$(ProjectName).dll"

Categories