构建文件夹中的所有解决方案
问题描述:
我正在尝试创建一个批处理脚本,该脚本将使用Visual Studio 2012的devenv.exe在一个文件夹中构建所有* .sln文件,我遇到了一些麻烦。使用下面的代码我得到“”forfiles“不被识别为内部或外部命令...”构建文件夹中的所有解决方案
我正在从运行Windows 7 Enterprise N 64位的计算机执行此操作。
@echo off
SET executablePath = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"
SET buildConfig = "Release"
cls
forfiles /m *.sln /c "cmd %executablePath% @file /build %buildConfig%"
答
我的批次是有点差,但如果你已经在PC上安装PowerShell的你可以使用这样的事情:
$SLNDirectory = "<Path_to_SLN_Files>"
$executablePath = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"
$buildConfig = "Release"
Clear
$Files = Get-ChildItem $SLNDirectory
Foreach($File in $Files){
$Extension = [System.IO.Path]::GetExtension($File).ToString()
If ($Extension -eq ".sln"){
$theFile = $File.Name
[Array]$SLNFiles +=$theFile
}
}
Foreach($SLNFile in $SLNFiles){
& "$executablePath $SLNFile /build $buildConfig"
}
答
试试这个(批处理脚本):
@echo off
SET "executablePath=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"
SET "buildConfig=Release"
cls
for %%i in (*.sln) do cmd /c "%executablePath%" "%%~i" /build %buildConfig%
+0
这不起作用。 – user2121236 2013-03-28 15:11:33
+0
你有错误信息吗? – Endoro 2013-03-28 16:29:06
这可能会起作用。我试图使用批处理文件,因为一些开发人员机器显然没有Powershell(或者至少没有设置文件关联)。 – user2121236 2013-03-28 15:12:38
您可以使用assoc命令更改文件关联:assoc .ps1 = C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe,然后查看您是否可以运行.ps1文件。尽管需要使用Admin权限从命令提示符运行Assoc。只要操作系统是Windows Vista或更高版本,Powershell应该被安装。如果他们有XP可以安装,但可能不值得从它的声音努力。 – 2013-03-28 15:33:52