Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

c# - Build Visual Studio project through the command line

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

I installed Vim on the server so that I can edit the files easily. If I edit HTML and CSS and .aspx pages, the updates are successful. But if I want to edit source code I would have to rebuild the project. Rebuilding the project recompiles everything nicely and updates the copy on the web. This is a development server so updates to everything is fine since no one sees this server.

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

The project is written in C# and the files are all in the wwwroot folder so no file moving needs to occur after a build.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Create a .bat file called: Manual_MSBuild_ReleaseVersion.bat

Put this in the .bat file.

REM you'll have to find the "latest" version of where msbuild.exe resides on your machine.. here are some popular versions/locations
REM set msBuildDir=%WINDIR%Microsoft.NETFrameworkv2.0.50727
REM set msBuildDir=%WINDIR%Microsoft.NETFrameworkv3.5
REM set msBuildDir=%WINDIR%Microsoft.NETFrameworkv4.0.30319
REM set msBuildDir=C:Program Files (x86)MSBuild12.0Bin
set msBuildDir=C:Program Files (x86)MSBuild14.0Bin

call "%msBuildDir%msbuild.exe"  MySolution.sln /p:Configuration=Release /l:FileLogger,Microsoft.Build.Engine;logfile=Manual_MSBuild_ReleaseVersion_LOG.log
set msBuildDir=

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

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

You can take it one step further:

rd .BuildResults /S /Q
md .BuildResults
rd .MyProjectBinRelease  /S /Q

REM you'll have to find the "latest" version of where msbuild.exe resides on your machine.. here are some popular versions/locations
REM set msBuildDir=%WINDIR%Microsoft.NETFrameworkv2.0.50727
REM set msBuildDir=%WINDIR%Microsoft.NETFrameworkv3.5
REM set msBuildDir=%WINDIR%Microsoft.NETFrameworkv4.0.30319
REM set msBuildDir=C:Program Files (x86)MSBuild12.0Bin
set msBuildDir=C:Program Files (x86)MSBuild14.0Bin
call "%msBuildDir%msbuild.exe"  MySolution.sln /p:Configuration=Release /l:FileLogger,Microsoft.Build.Engine;logfile=Manual_MSBuild_ReleaseVersion_LOG.log
set msBuildDir=

XCOPY .MyProjectBinRelease*.* .BuildResults

That way, you remove a directory (just to make sure you get a super clean build), create it, build the solution/project and then copy the results of the build to the fresh directory.

Super fresh, every time. And if the build blows up, the BuildResults directory is empty.

And a subtle little indicator, the datetime of the BuildResults directory is the last time you built (or tried to build) the solution/project. Subtle, but sometimes helpful.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...