简体   繁体   English

通过命令行构建 Visual Studio 项目

[英]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.我正在从 Windows Server 2008 安装运行 ASP.NET 网站,自从我通过 ssh 进入服务器后,我喜欢通过命令行编辑页面。

I installed Vim on the server so that I can edit the files easily.我在服务器上安装了Vim ,以便我可以轻松地编辑文件。 If I edit HTML and CSS and .aspx pages, the updates are successful.如果我编辑 HTML 和 CSS 以及 .aspx 页面,则更新成功。 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.该项目是用 C# 编写的,文件都在wwwroot文件夹中,因此构建后不需要进行文件移动。

Create a .bat file called: Manual_MSBuild_ReleaseVersion.bat创建一个名为:Manual_MSBuild_ReleaseVersion.bat 的 .bat 文件

Put this in the .bat file.把它放在 .bat 文件中。

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.NET\Framework\v2.0.50727
REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v3.5
REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319
REM set msBuildDir=C:\Program Files (x86)\MSBuild\12.0\Bin
set msBuildDir=C:\Program Files (x86)\MSBuild\14.0\Bin

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.您可以构建 .sln 文件或 .csproj 文件。 MySolution.sln or MyProject.csproj MySolution.sln 或 MyProject.csproj

See How to: Use MSBuild to Create a Web Package for more information.有关详细信息,请参阅如何:使用 MSBuild 创建 Web 包

You can take it one step further:你可以更进一步:

rd .\BuildResults /S /Q
md .\BuildResults
rd .\MyProject\Bin\Release  /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.NET\Framework\v2.0.50727
REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v3.5
REM set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319
REM set msBuildDir=C:\Program Files (x86)\MSBuild\12.0\Bin
set msBuildDir=C:\Program Files (x86)\MSBuild\14.0\Bin
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\

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.如果构建失败,\\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.还有一个微妙的小指标,\\BuildResults 目录的日期时间是您最后一次构建(或尝试构建)解决方案/项目的时间。 Subtle, but sometimes helpful.微妙,但有时很有帮助。

Maybe with this command:也许用这个命令:

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

You can find devenv in "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\devenv.exe" path.您可以在“C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\devenv.exe”路径中找到 devenv。

I used a modification of the answer by @granadaCoder above.我使用了上面@granadaCoder 对答案的修改。

For .NET version 4.5 onwards, there is no corresponding build directory in对于 .NET 4.5 及以后的版本,在

%WINDIR%\\Microsoft.NET\\Framework\\ %WINDIR%\\Microsoft.NET\\Framework\\

and using MSBuild for an older framework will not let you compile newer constructs like interpolated strings.并且将 MSBuild 用于较旧的框架不会让您编译较新的构造,例如内插字符串。

TO get around this, you'll need to install the latest MS Build Tools (2015 currently) and use MSBuild.exe in为了解决这个问题,你需要安装最新的MS Build Tools (目前2015年),并使用MSBuild.exe

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

Install the .NET SDK and use the MsBuild.exe command line tool.安装 .NET SDK 并使用 MsBuild.exe 命令行工具。 It's what Visual Studio uses when you build a project or solution.这是 Visual Studio 在生成项目或解决方案时使用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用命令行构建 Visual Studio 安装项目? - How to build Visual studio Setup project using command-line? 从命令行在2017 Visual Studio中构建项目? - Build project in 2017 Visual Studio from the command line? .Net Core Visual Studio 项目命令行构建与右键构建相同 - .Net Core Visual Studio project command line build same as right-clicking build 命令行生成解决方案与Visual Studio 2012生成 - Command line build solution vs Visual Studio 2012 build Visual Studio post build事件命令行“for”语法 - Visual studio post build event command line “for” syntax Visual Studio - 使用命令行更新项目服务引用 - Visual Studio - Update project service reference using command line 如何从命令行运行 Visual Studio 安装项目 - How to run the Visual Studio setup project from Command Line 使用Visual Studio可以很好地构建项目,但是从命令行失败 - Project builds fine with Visual Studio but fails from the command line Visual Studio用于通过msbuild命令行进行增量生成的生成目标 - Build target used by Visual Studio to do Incremental Build via msbuild command line 从帮助程序项目Visual Studio多个项目解决方案中获取命令行参数 - Getting command line arguments from the helper project visual studio multiple project solution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM