Programing

MS-Build 2017“Microsoft.WebApplication.targets”가 없습니다.

lottogame 2020. 11. 26. 07:44
반응형

MS-Build 2017“Microsoft.WebApplication.targets”가 없습니다.


빌드 서버 (jenkins)를 Visual Studio 2015에서 2017로 업그레이드하려고합니다. MS-Build를 통해 빌드하고 있습니다. 답변에 설명 된대로 MS-Buld 도구를 다운로드하고 설치했습니다 . 프로젝트를 컴파일하면 Microsoft.WebApplication.targets찾을 수없는 오류가 발생합니다 .

자세한 오류 :

 error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets"

MS-Build 디렉터리에서 찾기를 수행했습니다.

PS C:\Program Files (x86)\MSBuild> dir -Recurse -Filter "Microsoft.WebApplication.targets"


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


Mode                LastWriteTime         Length Name                                                                                                                                                                                                            
----                -------------         ------ ----                                                                                                                                                                                                            
-a----       11.01.2012     00:23          19654 Microsoft.WebApplication.targets                                                                                                                                                                                


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


Mode                LastWriteTime         Length Name                                                                                                                                                                                                            
----                -------------         ------ ----                                                                                                                                                                                                            
-a----       22.07.2013     01:25          19995 Microsoft.WebApplication.targets                                                                                                                                                                                


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


Mode                LastWriteTime         Length Name                                                                                                                                                                                                            
----                -------------         ------ ----                                                                                                                                                                                                            
-a----       06.07.2015     21:55          20118 Microsoft.WebApplication.targets                                                                                                                                                                                


    Directory: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\WebApplications


Mode                LastWriteTime         Length Name                                                                                                                                                                                                            
----                -------------         ------ ----                                                                                                                                                                                                            
-a----       22.07.2013     01:25          19995 Microsoft.WebApplication.targets

보시다시피 이전 컴파일러 버전에는 파일이 있지만 v15.0에는 누락되었습니다.

또한 빌드 서버에 Visual Studio 2017을 설치했습니다. Visual Studio 2017로 컴파일하면 프로젝트가 성공적으로 빌드됩니다.

이 문제를 해결하는 방법에 대한 힌트가 있습니까? 한 가지 가능한 솔루션은 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications지점에서 이전 v14.0 파일 (아래에 있음 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications) 로의 심볼릭 링크를 생성하는 것 입니다.

고마워


"웹 개발 빌드 도구"에 대한 워크로드가 누락 된 것 같습니다 Microsoft.VisualStudio.Workload.WebBuildTools..

여기 (VS2017) 또는 여기 (VS2019) 에서 빌드 도구 설치 프로그램을 다운로드 한 다음 실행 하여 설치할 수 있습니다.

vs_buildtools.exe --add Microsoft.VisualStudio.Workload.WebBuildTools

또는 vs_buildtools.exeGUI에서 "웹 개발 빌드 도구"구성 요소를 열고 선택합니다.

screenshot from GUI


위의 대답은 기술적으로 정확하지 않으며 적어도 저에게는 약간 혼란스럽고 Visual Build Professional이 작동하려면 추가 단계가 필요했습니다.

  1. vs_buildtools.exe does not technically exist. I had to create a question asking where that file was. It was not obvious that vs_buildtools.exe is vs_buildtools_*******.exe and is the actual installation program. Additionally the the "-add ***" mentioned above is just a shorthand. One can go to the GUI and check both workflow tasks. That does the same thing. I wound up having the vs_buildtools file, though not needing it.

  2. VSB Pro still did not build my project. I got thrown the same error above. The secret sauce was simply to copy the WebApplicationsfolder in C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0 to C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0. I then rebuilt the project and all was fine. I placed the WebApplication.targets file at the expected location.

Why Microsoft could not have done that is beyond me. Also, why the separate installation. VS17 installs an enormous amount of stuff. Build Tools is implied, like always. Whatever.

I am posting this answer as hopefully it will help others. I fell into the trap and lost quite a bit of time with my project not building. I hope that this answer clarifies things a bit.


I had a similar issue after having upgraded from Visual Studio 2015 to 2017. When I try to load the web application project, it throwed me the error message:

The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" was not found. Also, tried to find "WebApplications\Microsoft.WebApplication.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" . These search paths are defined in "C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\15.0_558e146f\devenv.exe.config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths.

The solution to this error I found here.

In my case, the .csproj file contained the following lines:

<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v14.0</VSToolsPath>
</PropertyGroup>

After replacing the v14.0 by v$(VisualStudioVersion) in the VSToolPath tag, the project could be loaded.

I also replaced the v14.0 by v10.0 in the VisualStudioVersion tag, as the solution in the above link shows. But for me it also worked by leaving it at 14.0.

Here is how these lines should look in the end:

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

If you don't have these lines at all in your .csproj, then you have to add them manually right BEFORE this line:

<Import Project="$(VSToolsPath)\Web\Microsoft.Web.Publishing.targets" Condition="'$(VSToolsPath)' != ''" />

In my case (slightly different error message but same problem) it was this line:

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

It seems that projects created with Visual Studio versions since 2011 contain the lines with the VSToolsPath redefinition, while older files did not. Visual Studio never added them automatically when upgrading to a newer VS version, which is why you should add them if they are not there.

Source of this information: https://developercommunity.visualstudio.com/content/problem/27735/project-fails-to-load-with-error-regarding-microso.html?childToView=123664#comment-123664 (click on Show more comments to see the full discussion thread - unfortunately I cannot directly link to comments in this "more" section.)


It is easy to install the 2017 build tools, with the WebBuildTools option already included, using chocolatey. Once you have installed it, type the following in an admin command prompt:

choco install visualstudio2017buildtools -y

For VS 2019, it's similar:

choco install visualstudio2019buildtools -y

Copy WebApplications folder from

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

to

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0

Or in your build script add the following line before compiling

Copy-Item "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications" "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications" -Recurse -Force

Be sure to run it with elevated permissions


how to create VS 2017 pro, asp.net MVC application and build it with Jenkins?

use vs 2017 pro in both dev machine and build server

Check that VisualStudio is set to 15
Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" Condition="false"

set the msbuild tool
to C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe in jenkins global configuration manager

With jenkins, execute windows command batch:
retore nugets: "C:\Program Files (x86)\Jenkins\tools\nuget\NuGet.exe" restore "C:\Program Files (x86)\Jenkins\workspace\theapp_build\theapp.sln"

With jenkins, execute windows command batch:
MSBuild Build File: theapp.sln
Command Line Arguments: /nologo /t:restore /t:rebuild /p:Configuration="Debug" /p:VisualStudioVersion=15.0

참고URL : https://stackoverflow.com/questions/44061932/ms-build-2017-microsoft-webapplication-targets-is-missing

반응형