通过命令行构建 Visual Studio 项目 [英] Build Visual Studio project through the command line

查看:30
本文介绍了通过命令行构建 Visual Studio 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 Windows Server 2008 安装运行 ASP.NET 网站,自从我通过 ssh 进入服务器后,我喜欢通过命令行编辑页面.

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.

我在服务器上安装了 Vim 以便我可以轻松编辑文件.如果我编辑 HTML 和 CSS 以及 .aspx 页面,则更新成功.但是如果我想编辑源代码,我将不得不重建项目.重建项目可以很好地重新编译所有内容并更新网络上的副本.这是一个开发服务器,所以更新一切都很好,因为没有人看到这个服务器.

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?

该项目是用 C# 编写的,文件都在 wwwroot 文件夹中,因此构建后不需要移动文件.

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.

推荐答案

创建一个名为:Manual_MSBuild_ReleaseVersion.bat

Create a .bat file called: Manual_MSBuild_ReleaseVersion.bat

将其放入 .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=

您可以构建 .sln 文件或 .csproj 文件.MySolution.sln 或 MyProject.csproj

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

请参阅如何:使用 MSBuild 创建 Web 包 了解更多信息.

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

你可以更进一步:

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.

每次都超级新鲜.如果构建失败,BuildResults 目录为空.

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

还有一个微妙的小指标,BuildResults 目录的日期时间是您最后一次构建(或尝试构建)解决方案/项目的时间.微妙,但有时很有帮助.

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.

这篇关于通过命令行构建 Visual Studio 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆