简体   繁体   English

如何使用批处理文件构建解决方案

[英]How to build solution using batchfile

I want to build .NET solution using batch file. 我想使用批处理文件构建.NET解决方案。

I am aware that I need to use following statement 我知道我需要使用以下声明

devenv /build release "D:\Source Code\Source\test.sln"

But I do not know how to create batch file which will execute on VS command prompt. 但我不知道如何创建将在VS命令提示符下执行的批处理文件。

The visual studio command prompt just loads some variables and path settings. visual studio命令提示符只加载一些变量和路径设置。 That's all it is, it's nothing specially, it's not a different command prompt, it's the same command prompt with some settings configured. 就是这样,它没有什么特别的,它不是一个不同的命令提示符,它是配置了一些设置的相同命令提示符。 You can load the same settings in your own batch file by including the following line at the top: 您可以在自己的批处理文件中加载相同的设置,方法是在顶部包含以下行:

call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86

(Obviously, for different versions of VS, the path might change slightly) (显然,对于不同版本的VS,路径可能会略有变化)

You can replace "x86" with the appropriate architecture for your machine. 您可以将“x86”替换为适合您机器的架构。 The permitted values are: 允许的值是:

  • x86 86
  • amd64 AMD64
  • x64 64位
  • ia64 IA64
  • x86_amd64 x86_amd64
  • x86_ia64 x86_ia64

That said, I don't think you actually need to load all the vars/paths all you really need to do is provide the full path to the devenv.exe file. 也就是说,我认为你真的不需要加载所有你需要做的vars /路径就是提供devenv.exe文件的完整路径。 You could try this instead: 你可以试试这个:

"c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" /build release "D:\Source Code\Source\test.sln"

(Again, the path will change for different versions of visual studio) (同样,对于不同版本的visual studio,路径会发生变化)

The sample batch file below will detect the install directory that contains devenv.exe by looking it up in the registry (for VS2005, can easily be adapted for other versions) and executes devenv.exe. 下面的示例批处理文件将检测包含devenv.exe的安装目录,方法是在注册表中查找(对于VS2005,可以很容易地适用于其他版本)并执行devenv.exe。 Is this what you're looking for? 这是你在找什么?

@echo off

CALL :GETVS2005DIR
IF "%VS2005DIR%" == "" GOTO NOVS2005
IF NOT EXIST "%VS2005DIR%" GOTO NOVS2005

%VS2005DIR%devenv.exe ...
GOTO :EOF

:GETVS2005DIR
for /f "tokens=1,2* delims= " %%i in ('reg query HKLM\Software\Microsoft\VisualStudio\8.0 /v InstallDir') do set VS2005DIR=%%k
GOTO :EOF

:NOVS2005
echo.
echo Visual Studio 2005 installation directory not found
echo.
GOTO :EOF

Note also that as long as your solution does not contain a Setup project, you will normally be able to build it using MSBUILD, which is simpler and works on a machine without Visual Studio installed: 另请注意,只要您的解决方案不包含安装项目,您通常就可以使用MSBUILD构建它,这更简单,适用于未安装Visual Studio的计算机:

REM Check MsBuild is available (this is for V2.0, use a different version if desired)
SET MSBUILD=%WINDIR%\Microsoft.NET\Framework\v2.0.50727\MsBuild.exe
IF NOT EXIST "%MSBUILD%" GOTO NOMSB

"%MSBUILD%" MySolution.sln /t:rebuild /p:configuration=Debug /verbosity:quiet 
GOTO :EOF

:NOMSB
echo. 
echo MSBUILD not found 
echo. 
GOTO :EOF 

Not sure if I understand the question. 不确定我是否理解这个问题。

Just create a file called test.bat, add the statement you've written above to that file and then just open a VS command prompt and type [pathtobatfile]\\test.bat. 只需创建一个名为test.bat的文件,将上面写的语句添加到该文件中,然后只需打开VS命令提示符并键入[pathtobatfile] \\ test.bat即可。

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

相关问题 如何使用MSBuild仅构建解决方案中包含的少数几个项目? - How to build only a handful of projects contained in a solution using MSBuild? 使用GitLab CI Pipeline构建.NET解决方案 - Build .NET solution using GitLab CI Pipeline 尝试使用Inedo BuildMaster进行构建的.Net解决方案 - .Net solution trying to build using Inedo BuildMaster 在不使用 Visual Studio 的情况下清理和构建解决方案 - Clean and Build a solution without using Visual Studio 如何通过构建将nuget包添加到项目(不是解决方案) - How to add nuget package to project (not solution) with build 如何为多个目标框架构建解决方案? - How to build a solution for mutliple target frameworks? 如何从PowerShell构建VS解决方案文件夹 - How to build VS solution folder from powershell 使用MSBuild,如何从命令行构建MVC4解决方案(在此过程中应用Web.config转换)并输出到文件夹? - Using MSBuild, how do I build an MVC4 solution from the command line (applying Web.config transformations in the process) and output to a folder? 如何使用64位MSBuild构建ac#解决方案? - How to build a c# solution with 64 bit MSBuild? 如何使用来自Web服务的数据构建可伸缩的报告解决方案? - How to build a scalable Reporting Solution with data from a web service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM