17

I have a solution file comprising of 15 projects using a few third party dll references. I want to be able to build the solution from a batch file. What is the best way to do this?

Thanks

3
  • Is your goal build automation? If so there are a lot of tools out there to facilitate this (more robust than creating .bat files anyway). Commented Oct 7, 2010 at 19:46
  • @BrandonBoone any best one? Commented May 22, 2014 at 12:26
  • @iSid - I've had some success with Cruise Control for continuous build automation. It'll integrate with your Source Control repository and rebuild your projects when you check-in changes. I believe it can also run your unit tests. Commented Jun 18, 2014 at 20:44

3 Answers 3

30

Run msbuild - for example:

msbuild MySolution.sln /p:Configuration=Release /p:Platform="Any CPU"
Sign up to request clarification or add additional context in comments.

4 Comments

How do i run it after this line? The above ,line dose not create an exe file by me.
@YTG: It should do if any of the projects is configured to build an executable. (Normally I'd suggest using dotnet build these days of course - bear in mind this answer is over 12 years old.) It sounds like you probably need to write a new question with a lot more context.
It is configured. I have <OutputType>Exe</OutputType> in my csprog file. Im looking inside all the folders in bin but there is no exe file to be found.
@YTG: Again, please ask a new question rather than trying to ask a question in comments on a 12 year old post...
20

One of the simplest ways is to execute msbuild with the solution file as input:

@echo off
call %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe path\to\solution.sln

If this is done in a Visual Studio command prompt you can skip the path to msbuild.exe.

Comments

3

One way to get started is to open the project in Visual Studio and select Build | Rebuild Solution. Then go to View | Output. In the output window select "Build" in the Show Options From dropdown. This will display the commands that Visual Studio is using to build the project. You can paste those into a batch file, and read or modify them as desired.

If you want to maintain both Debug and Release versions of your application, then you will want to select the correct configuration and then follow the above steps for each version.

4 Comments

Can someone explain the down vote? Is the information not correct? Does it not address the question asked?
I think it's because he asked how to build a solution from a batch file but your solution uses visual studio to perform a build and doesn't answer his question.
@TomMiller - I am only using Visual Studio as a simple way to generate the batch command. I am not telling him how to build it in VS.
By default it only shows the ouput from the commands, not the commands themselves (minimal). You can go into Tools | Options, then Projects & solutions, then Build & Run. There you can change the output verbosity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.