14

I am copying .exe file form a separate to my main project's folder on prebuild event but I need to build that project before build my main project so i want to build that project on prebuild event of my main project.

Govind Malviya
  • 13,627
  • 17
  • 68
  • 94
  • 3
    A better solution (if read in 2018) would be to setup a project dependency, see instructions at: https://stackoverflow.com/a/2868986/2193151 – Bonghi Oct 28 '18 at 18:52

4 Answers4

13

This is what worked for me:

"$(DevEnvDir)devenv" "$(SolutionDir)MySolution.sln" /Build $(configuration) /project "$(SolutionDir)MyProjectFolder\MyProject.csproj"

Here $(DevEnvDir), $(SolutionDir), and $(configuration) are Visual Studio Macros, so this command will be translated into:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv" "D:\Learning\MySolutionFolder\MySolutionName.sln" /Build Debug /project "D:\Learning\MySolutionFolder\MyProjectFolder\MyProject.csproj"
inejwstine
  • 678
  • 1
  • 10
  • 30
Mykhailo Seniutovych
  • 3,527
  • 4
  • 28
  • 50
12

Not that this is the best solution, but it will definitely work for what you want to do: Put the below into your pre-build event

"$(VS100COMNTOOLS)..\IDE\devenv" "csproj location OR sln location" /Rebuild "configuration required if you have more than configuration ex: Debug|x64"

Dale K
  • 25,246
  • 15
  • 42
  • 71
Jason Pugh
  • 136
  • 2
  • 3
  • 6
    Thank for this! I use Visual studio 2015 and now it will looks like `"$(DevEnvDir)\devenv" "csproj location OR sln location" /Rebuild "configuration required if you have more than configuration ex: Debug|x64"` – Sousuke Sep 11 '15 at 12:22
0
"$(DevEnvDir)devenv" "$(SolutionPath)" /Rebuild $(configuration) /project "$(SolutionDir)MyProjectFolder\MyProject.csproj"

Tested now on Visual Studio Community 16.11.1

GioviQ
  • 75
  • 1
  • 9
0

Using the below command in visual studio 2019, build is faster with msbuild as compared to "$(DevEnvDir)devenv".

msbuild "$(SolutionDir)Sample.sln" /p:configuration=$(configuration)

Shashank
  • 116
  • 1
  • 5