Programing

Visual Studio 2012 솔루션의 TeamCity에서 MSBuild

lottogame 2020. 10. 29. 07:47
반응형

Visual Studio 2012 솔루션의 TeamCity에서 MSBuild


TeamCity에서 빌드하려는 VS 2012 웹 프로젝트 / sln이 있습니다. TeamCity에 설치된 .NET 4.5를 사용합니다.

TeamCity 서버에는 VS 2010 만 설치되어 있습니다 .

빌드가 실행될 때이 오류가 발생합니다.

C:\BuildAgent\work\d5bc4e1b8005d077\CUSAAdmin.Web\CUSAAdmin.Web.csproj(799, 3): 
error MSB4019: 
The imported project 
    "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. 
 Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. Project CUSAAdmin.Web\CUSAAdmin.Web.csproj failed. 
 Project CUSAAdmin.sln failed. 

Visual Studio 2012 (v11.0)를 사용하여 빌드하려고합니다.

그래도 build.xml 에서 VisualStudioVersion10 으로 설정했습니다 . ??

 <Target Name="BuildPackage">
   <MSBuild Projects="CUSAAdmin.sln" ContinueOnError="false" 
     Targets="Rebuild" 
      Properties="Configuration=$(Configuration); VisualStudioVersion=10.0"  />

프로젝트 내에서도 VS2010으로 기본 설정됩니다.

  <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath 
    Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

실제로 CI 서버에 Visual Studio를 설치할 필요가 없습니다. 개발 시스템에서 CI 서버의 동일한 위치로 몇 개의 폴더 만 복사하면됩니다.

VS 2015 :

  • C : \ Program Files (x86) \ MSBuild \ Microsoft \ VisualStudio \ v14.0 \ Web
  • C : \ Program Files (x86) \ MSBuild \ Microsoft \ VisualStudio \ v14.0 \ WebApplications

VS 2013 :

  • C : \ Program Files (x86) \ MSBuild \ Microsoft \ VisualStudio \ v12.0 \ Web
  • C : \ Program Files (x86) \ MSBuild \ Microsoft \ VisualStudio \ v12.0 \ WebApplications

VS 2012 :

  • C : \ Program Files (x86) \ MSBuild \ Microsoft \ VisualStudio \ v11.0 \ Web
  • C : \ Program Files (x86) \ MSBuild \ Microsoft \ VisualStudio \ v11.0 \ WebApplications

VS 2010 :

  • C : \ Program Files (x86) \ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ Web
  • C : \ Program Files (x86) \ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ WebApplications

.NET 4.6 :

  • C : \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.6

.NET 4.5.2 :

  • C : \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.5.2

.NET 4.5.1 :

  • C : \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.5.1

.NET 4.5 :

  • C : \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.5

.NET 4.0.1 :

  • C : \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.0.1

.NET 4.0 :

  • C : \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.0

또는 Matt가 제안한 대로 프로젝트의 하위 디렉터리에 복사하고 <MSBuildExtensionsPath32>MSBuild (일반적으로 .csproj또는 .vbproj) 파일 위치를 변경할 수 있습니다.

이 작업을 마치면 프로젝트가 컴파일됩니다. VisualStudioVersion을 사용중인 버전으로 명시 적으로 설정하여 올바르게 설정되었는지 확인해야합니다.

참고 : 이 솔루션은 모든 프로젝트 유형 (웹 프로젝트 포함)에서 작동합니다. 프로젝트 파일이없는 웹 사이트의 경우 빌드하지 못하게하는 레지스트리 키가 누락 되었기 때문에 사용중인 .NET SDK 버전과 일치하는 Windows SDK를 설치 했습니다.


정말 간단합니다. MSBuild가 TeamCity에서 VS2012로 만든 솔루션의 빌더로 VS2010을 실행하도록하려면 다음과 같이 빌드 구성에 대한 환경 변수를 설정하면됩니다.

enter image description here

Name: env.VisualStudioVersion 
Value: 10.0

참고 TeamCity에는 VS2012를 설치할 필요가 없습니다.


또는 c : \ Program Files (x86) \ MSBuild에서 필요한 빌드 대상을 프로젝트의 하위 디렉터리 (예 :. \ Build)로 복사하여 구조를 유지하고 csproj에 다음을 추가 할 수 있습니다.

<!-- redirect msbuild path so targets can be added to source control -->
<PropertyGroup>
  <MSBuildExtensionsPath32>..\Build\</MSBuildExtensionsPath32>
</PropertyGroup>

예를 들어, 내 프로젝트 루트가 C : \ Dev \ MyProjSln \ MyProj 인 경우

  • Create Folder C:\Dev\MyProjSln\Build\Microsoft\VisualStudio\version\WebApplications\
  • Copy Contents of C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\version>\WebApplications\ to created folder
  • Add MSBuildExtensionsPath32 element to Property Group under Project node in csproj
  • Profit!

Personally, I prefer this method of tracking build target dependencies, as it prevents build server from being dependent on having undocumented folder structure requirements, and gets your dependencies into source control


As described here:

  • Install nuget MSBuild.Microsoft.VisualStudio.Web.targets
  • Edit the .csproj file

Replace:

<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /> 
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

with:

<Import Project="..\packages\MSBuild.Microsoft.VisualStudio.Web.targets.11.0.2.1\tools\VSToolsPath\WebApplications\Microsoft.WebApplication.targets" Condition="true" />

Obviously you have to make sure versions match your case both on the nuget installed and path in <Import>


I totally disagree with changing the project files because that might affect other developers. This is what worked for me since the v11.0 folder was missing on MS build folder: 1)Create v111.

  1. Create v11.0 folder on C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio
  2. Copy Web and WebApplications folders from my development box "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0"
  3. Booom! work like a charm\
  4. Note: I installed "Microsoft Visual Studio 2012 Shell (Isolated) Redistributable Package"

Firstly, TeamCity does not require presence of Visual Studio of any version to build. When a build step in the project is configured with MSBuild runner TeamCity needs to know which version of MSBuild to use. This is a setting of a build step. Proper MSBuild version must be selected in a build step configuration according to the .NET tools installed on a build machine. TeamCity will use that value to determine the location path and will set an environment variable when invokes MSBuild.

The problem with the Visual Studio 2012/2013 is that it's only supported by TeamCity starting 8.1.0. So if your TeamCity version is before 8.1. you need to upgrade to the latest 8.1.x to see a setting for MSBuild Tools 2013. Once you select a proper MSBuild version in the build step settings the problem will disappear. For more information read here: http://blog.turlov.com/2014/07/upgrade-teamcity-to-enable-support-for.html

참고URL : https://stackoverflow.com/questions/15419610/msbuild-in-teamcity-of-visual-studio-2012-solution

반응형