问题描述
我们正在运行一个Team City Build Server,并且希望编译一个Visual C ++项目.到目前为止,这很容易,因为我已经使用Windows SDK设置了Windows Build Agent,但是我们没有解决方案/项目文件.
项目文件而是使用CMake创建的. CMake似乎有点愚蠢(未安装Visual Studio时无法生成解决方案),但是通过一些技巧,我可以做到这一点.然后可以使用MSBuild构建该解决方案.
问题来了.为了自动运行,我需要调用Windows SDK的SetEnv.cmd.而且我似乎无法自动找到它.它位于Windows SDK的bin子目录中,但bin和root都不在路径中,并且%mssdk%
环境变量由SetEnv.cmd 设置,并且事先不可用! /p>
将Windows SDK \ bin目录添加到PATH会导致SetEnv.cmd不再起作用(退出,并显示诸如The x86 compilers are not currently installed
和Jump target Set_x86 not found
之类的消息.
开始菜单链接正在使用Windows SDK目录作为工作目录来调用SetEnv.cmd.但是,如果我将根目录添加到PATH,则Bin \ SetEnv.cmd不可用.
如何自动找到SetEnv.cmd?即使将环境变量设置为setenv.cmd的完整路径也不起作用,并且当我将%mssdk%定义为sdk目录时,则调用%mssdk%\ bin \ SetEnv也不起作用.我还尝试定义%mssdk%,然后定义cd%mssdk%,然后调用bin \ SetEnv.同样,在所有这些情况下都找不到编译器.如果我在命令行上手动CD到根目录或bin目录,然后调用SetEnv.cmd ...,
开始菜单链接仍然可以正常工作.
出于记录,我目前的解决方案如下:
我创建了一个MSBuild文件,该文件在命令行上使用CMake创建了解决方案文件,然后使用MSBuild任务调用了创建的解决方案. MSBuild文件可以从TeamCity轻松构建,尽管我需要一些其他技巧来满足CMake愚蠢的寻找编译器的需要,尽管我不会调用它.并不是很令人满意,但是可以.
我的解决方案(设置了%WindowsSdkPath%
,因此可以在%WindowsSdkPath%Bin\
下找到SetEnv.cmd
):
@ECHO OFF
IF "%WindowsSdkVersion%"=="" (
CALL :SetWindowsSdkVersionHelper HKCU > nul 2>&1
IF ERRORLEVEL 1 CALL :SetWindowsSdkVersionHelper HKLM > nul 2>&1
IF ERRORLEVEL 1 GOTO ERROR_NOWSDK
)
CALL :SetWindowsSdkPathHelper > nul 2>&1
IF ERRORLEVEL 1 GOTO ERROR_NOWSDK
GOTO END
:SetWindowsSdkPathHelper
SET WindowsSdkPath=
FOR /F "tokens=1,2*" %%i in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\%WindowsSdkVersion%" /V InstallationFolder') DO (
IF "%%i"=="InstallationFolder" (
SET "WindowsSdkPath=%%k"
)
)
IF "%WindowsSdkPath%"=="" EXIT /B 1
EXIT /B 0
:SetWindowsSdkVersion
CALL :GetWindowsSdkVersionHelper HKCU > nul 2>&1
IF ERRORLEVEL 1 CALL :GetWindowsSdkVersionHelper HKLM > nul 2>&1
IF ERRORLEVEL 1 EXIT /B 1
EXIT /B 0
:SetWindowsSdkVersionHelper
SET WindowsSdkVersion=
FOR /F "tokens=1,2*" %%i in ('REG QUERY "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /V "CurrentVersion"') DO (
IF "%%i"=="CurrentVersion" (
SET "WindowsSdkVersion=%%k"
)
)
IF "%WindowsSdkVersion%"=="" EXIT /B 1
EXIT /B 0
:ERROR_NOWSDK
ECHO The Windows SDK %WindowsSdkVersion% could not be found.
EXIT /B 1
:END
SetEnv.cmd
本身就是我的灵感所在……
We have a Team City Build Server running and want to compile a Visual C++ project. So far this would be easy, since I've setup our Windows Build Agent with the Windows SDK, but we don't have a solution / project file.
The project files are instead created with CMake. CMake seems to be a little bit dumb (can't generate Solution when Visual Studio is not installed), but with some tricks, I could get it to do it. The solution can then be built with MSBuild.
And here comes the problem. For this to work automatically, I need to call the Windows SDK's SetEnv.cmd. And I can't seem to find it automatically. It's in the bin sub directory of the Windows SDK, but neither bin nor the root are in the path, and the %mssdk%
environment variable is set by the SetEnv.cmd and is not available beforehand!
Adding the Windows SDK\bin dir to the PATH leads to SetEnv.cmd no longer working (exits with a message like The x86 compilers are not currently installed
and Jump target Set_x86 not found
.
The start menu link is calling the SetEnv.cmd with the Windows SDK dir as working directory instead. But if I add the root directory to the PATH, Bin\SetEnv.cmd is not available.
How can I find SetEnv.cmd automatically? Even setting an environment variable to the full path of the setenv.cmd doesn't work, and when I define %mssdk% as the sdk dir, then call %mssdk%\bin\SetEnv doesn't work as well. I also tried to define %mssdk%, then cd %mssdk%, then calling bin\SetEnv. Also compilers not found in all these cases. It also doesn't work if I manually cd to the root or bin dir on a command line and then call SetEnv.cmd...
The start menu link works fine though.
For the record, my solution for now, as strange as this is, is the following:
I created a MSBuild file that creates the solution file with CMake on the command line, then invokes the created solution with a MSBuild task. The MSBuild file can be easily built from TeamCity, though I needed some additional tricks to satisfy CMake's stupid looking for the compiler, though I won't invoke it thing. Not really satisfying, but it works.
My solution (sets %WindowsSdkPath%
, so that SetEnv.cmd
could be found under %WindowsSdkPath%Bin\
):
@ECHO OFF
IF "%WindowsSdkVersion%"=="" (
CALL :SetWindowsSdkVersionHelper HKCU > nul 2>&1
IF ERRORLEVEL 1 CALL :SetWindowsSdkVersionHelper HKLM > nul 2>&1
IF ERRORLEVEL 1 GOTO ERROR_NOWSDK
)
CALL :SetWindowsSdkPathHelper > nul 2>&1
IF ERRORLEVEL 1 GOTO ERROR_NOWSDK
GOTO END
:SetWindowsSdkPathHelper
SET WindowsSdkPath=
FOR /F "tokens=1,2*" %%i in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\%WindowsSdkVersion%" /V InstallationFolder') DO (
IF "%%i"=="InstallationFolder" (
SET "WindowsSdkPath=%%k"
)
)
IF "%WindowsSdkPath%"=="" EXIT /B 1
EXIT /B 0
:SetWindowsSdkVersion
CALL :GetWindowsSdkVersionHelper HKCU > nul 2>&1
IF ERRORLEVEL 1 CALL :GetWindowsSdkVersionHelper HKLM > nul 2>&1
IF ERRORLEVEL 1 EXIT /B 1
EXIT /B 0
:SetWindowsSdkVersionHelper
SET WindowsSdkVersion=
FOR /F "tokens=1,2*" %%i in ('REG QUERY "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /V "CurrentVersion"') DO (
IF "%%i"=="CurrentVersion" (
SET "WindowsSdkVersion=%%k"
)
)
IF "%WindowsSdkVersion%"=="" EXIT /B 1
EXIT /B 0
:ERROR_NOWSDK
ECHO The Windows SDK %WindowsSdkVersion% could not be found.
EXIT /B 1
:END
I was inspired for this by the SetEnv.cmd
itself...
这篇关于如何找到Windows SDK的SetEnv.cmd/SetEnv.cmd无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!