Build a Visual Studio project through the command line

I run the ASP.NET website from a Windows Server 2008 installation, and I like to edit pages through the command line, since I am ssh on the server.

I installed Vim on the server so that I can easily edit the files. If I edit HTML and CSS and .aspx pages, the updates will succeed. But if I want to edit the source code, I have to rebuild the project. Project Recovery completely recompiles and updates the copy online. This is a development server, so updates for everyone are great, since no one sees this server.

How can I build a project through the command line to update the source code and build on the server?

The project is written in C #, and all the files are in the wwwroot folder, so after the build the file should not be moved.

+19
c # command cmd build windows-server-2008
Apr 14 2018-11-21T00:
source share
4 answers

Create a .bat file called: Manual_MSBuild_ReleaseVersion.bat

Put this in a .bat file.

 REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v3.5 set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319 call %msBuildDir%\msbuild.exe MySolution.sln /p:Configuration=Release /l:FileLogger,Microsoft.Build.Engine;logfile=Manual_MSBuild_ReleaseVersion_LOG.log set msBuildDir= 

You can create a .sln file or a .csproj file. MySolution.sln or MyProject.csproj

See How to Use MSBuild to Build a Web Package for more information.

You can do it one more step:

 rd .\BuildResults /S /Q md .\BuildResults rd .\MyProject\Bin\Release /S /Q REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v3.5 set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319 call %msBuildDir%\msbuild.exe MySolution.sln /p:Configuration=Release /l:FileLogger,Microsoft.Build.Engine;logfile=Manual_MSBuild_ReleaseVersion_LOG.log set msBuildDir= XCOPY .\MyProject\Bin\Release\*.* .\BuildResults\ 

This way you delete the directory (just make sure you get a super clean assembly), create it, create a solution / project and copy the assembly results to a new directory.

Super fresh every time. And if the assembly explodes, the \ BuildResults directory is empty.

And a thin little indicator, the \ BuildResults catalog datetime is the last time you built (or tried to build) a solution / project. Thin, but sometimes useful.

+34
Apr 14 2018-11-21T00:
source share

I used a modification of the answer from @granadaCoder above.

For .NET version 4.5 in the directory

there is no corresponding layout directory,

% WINDIR% \ Microsoft.NET \ Framework \

and using MSBuild for the old structure will not allow you to compile new constructs such as interpolated strings.

To get around this, you need to install the latest version of MS Build Tools (2015 currently) and use MSBuild.exe in

% ProgramFiles (x86)% \ MSBuild \ 14.0 \ Bin

+5
Feb 19 '17 at 12:29
source share

Perhaps with this command:

  >> devenv myproject.sln /Build "Release|x86" 

You can find devenv in the path "C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ devenv.exe".

+4
Nov 04 '15 at 15:59
source share

Install the .NET SDK and use the MsBuild.exe command-line tool. This is what Visual Studio uses when creating a project or solution.

+3
Apr 14 2018-11-11T00:
source share



All Articles