programing tip

명령 줄에서 Visual Studio 프로젝트를 어떻게 컴파일합니까?

itbloger 2020. 8. 15. 08:49
반응형

명령 줄에서 Visual Studio 프로젝트를 어떻게 컴파일합니까?


Monotone , CMake , Visual Studio Express 2008 및 사용자 지정 테스트를 사용하는 대규모 C ++ 솔루션에 대한 체크 아웃, 빌드, 배포, 테스트 및 커밋주기를 스크립팅하고 있습니다.

다른 모든 부분은 매우 간단 해 보이지만 GUI없이 Visual Studio 솔루션을 컴파일하는 방법을 알 수 없습니다.

스크립트는 Python으로 작성되었지만 os.system을 호출하면됩니다.


두 가지 방법을 알고 있습니다.

방법 1
(내가 선호하는) 첫 번째 방법은 msbuild 를 사용하는 것입니다 .

msbuild project.sln /Flags...

방법 2 다음
을 실행할 수도 있습니다.

vcexpress project.sln /build /Flags...

vcexpress 옵션은 즉시 반환되며 출력을 인쇄하지 않습니다. 나는 그것이 당신이 스크립트에 원하는 것일 수 있다고 생각합니다.

DevEnv는 Visual Studio Express 2008과 함께 배포되지 않습니다 (처음 비슷한 문제가 발생했을 때이를 파악하기 위해 많은 시간을 보냈습니다).

따라서 최종 결과는 다음과 같습니다.

os.system("msbuild project.sln /p:Configuration=Debug")

msbuild 및 vcexpress는 기본적으로 시스템 경로에 없기 때문에 환경 변수가 올바른지 확인해야합니다. Visual Studio 빌드 환경을 시작하고 여기에서 스크립트를 실행하거나 Python에서 경로를 수정합니다 ( os.putenv 사용 ).


MSBuild는 일반적으로 작동하지만 이전에 어려움을 겪었습니다. 당신은 더 나은 행운을 가질 수 있습니다

devenv YourSolution.sln /Build 

솔직히 말해서 2 센트를 더해야합니다.

msbuild.exe로 할 수 있습니다 . msbuild.exe 에는 여러 버전이 있습니다 .

C : \ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727 \ msbuild.exe C : \ Windows \ Microsoft.NET \ Framework64 \ v3.5 \ msbuild.exe C : \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ msbuild.exe
C : \ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ msbuild.exe C : \ Windows \ Microsoft.NET \ Framework \ v3.5 \ msbuild.exe C : \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ msbuild.exe

필요한 버전을 사용하십시오. 기본적으로 마지막 것을 사용해야합니다.

C : \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ msbuild.exe

그래서 그것을하는 방법.

  1. COMMAND실행

  2. msbuild.exe의 경로를 입력하십시오.

C : \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ msbuild.exe

  1. 다음과 같은 프로젝트 솔루션의 경로를 입력하십시오.

"C : \ Users \ Clark.Kent \ Documents \ visual studio 2012 \ Projects \ WpfApplication1 \ WpfApplication1.sln"

  1. 솔루션 경로 뒤에 필요한 플래그를 추가하십시오.

  2. Enter 키를 누릅니다.

다음과 같은 가능한 모든 플래그에 대한 도움을받을 수 있습니다.

C : \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ msbuild.exe / help


msbuild다른 사람들이 지적한대로 사용 하는 것이 저에게는 효과가 있었지만 그 이상을해야했습니다. 먼저 msbuild컴파일러에 대한 액세스 권한이 있어야합니다. 다음을 실행하여 수행 할 수 있습니다.

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"

그런 다음 msbuild내 $ PATH에 없으므로 명시 적 경로를 통해 실행해야했습니다.

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" myproj.sln

마지막으로 내 프로젝트는 $(VisualStudioDir). 그것들이 설정되지 않은 것 같아서 옵션을 msbuild통해 수동으로 설정해야했습니다 /property.

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" /property:VisualStudioDir="C:\Users\Administrator\Documents\Visual Studio 2013" myproj.sln

그 라인은 마침내 제가 프로젝트를 컴파일 할 수있게 해주었습니다.

Bonus: it seems that the command line tools do not require a registration after 30 days of using them like the "free" GUI-based Visual Studio Community edition does. With the Microsoft registration requirement in place, that version is hardly free. Free-as-in-facebook if anything...


MSBuild is your friend.

msbuild "C:\path to solution\project.sln"

DEVENV works well in many cases, but on a WIXPROJ to build my WIX installer, all I got is "CATASTROPHIC" error in the Out log.

This works: MSBUILD /Path/PROJECT.WIXPROJ /t:Build /p:Configuration=Release

참고URL : https://stackoverflow.com/questions/498106/how-do-i-compile-a-visual-studio-project-from-the-command-line

반응형