2013-03-27 120 views
1

我正在嘗試創建一個批處理腳本,該腳本將使用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%" 

回答

0

我的批次是有點差,但如果你已經在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" 
} 
+0

這可能會起作用。我試圖使用批處理文件,因爲一些開發人員機器顯然沒有Powershell(或者至少沒有設置文件關聯)。 – user2121236 2013-03-28 15:12:38

+0

您可以使用assoc命令更改文件關聯:assoc .ps1 = C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe,然後查看您是否可以運行.ps1文件。儘管需要使用Admin權限從命令提示符運行Assoc。只要操作系統是Windows Vista或更高版本,Powershell應該被安裝。如果他們有XP可以安裝,但可能不值得從它的聲音努力。 – 2013-03-28 15:33:52

0

試試這個(批處理腳本):

@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

相關問題