How to run executable from a different folder? - c#

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

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)"

How to copy an EXE from a .net core app's bin directory into wwwroot without knowing the build configuration?

I have an exe being dropped into my bin directory however sometimes this exe will be dropped into debug or release. Is there any way to - from a post-build event - say "hey, wherever we built this thing, copy it into the wwwroot folder"?
I see the following: http://www.benramey.com/2010/06/29/visual-studio-post-build-event-to-copy-dlls/
Where this code is used:
cd $(ProjectDir)
copy /y bin\debug\*.dll C:\inetpub\wwwroot\wss\VirtualDirectories\{YOUR SHAREPOINT SITE DIRECTORY}\bin
However I want to not specify debug or release or netcoreapp2.0 or netcoreapp:
How can this be achieved?
Use the provided macros. You already used $(ProjectDir).
$(TargetPath) will contain the complete path to the executable.
$(OutDir) will contain the output directory (relative).

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

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\"

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.

Is there a command that includes files in a project of Visual Studio 2010?

I'm developing a web project that consists from many other projects, so
when I build my main project I need to copy some resource files to the folder of main project
and make all copied files as included in this project.
I'm using post event feature for doing this.
xcopy /E /Y "SourcePath1" "$(ProjectDir)Scripts\"
xcopy /E /Y "SourcePath2" "$(ProjectDir)Scripts\"
xcopy /E /Y "SourcePath3" "$(ProjectDir)Scripts\"
this command copies my files, but these files are not included in the project. What command can I use for including copied files?
I need something like
include "pathtwherefilesare"
Thanks!
There is a icon in the solution explorer to "show all files". Then you can include (right click) these files to your project.
you can copy once, and add copied files to project, then commands will replace old files with new ones
Hope this helps
If your project is a web application project (as opposed to web site project), try Add Existing Items, select the files, and select Add as Link from the Add button dropdown menu.
Edit the files' Build Action and Copy to Output Directory settings as required.

Categories