在生成服务器上找不到 Microsoft.WebApplication.targets。你的解决方案是什么?
尝试在生成服务器上生成我的项目时出现以下错误:
Microsoft (R) Build Engine Version 4.0.30319.1
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.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.
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.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.
几个月前,我通过在生成服务器上安装 Visual Studio 2010 解决了这个问题。但现在我正在从头开始设置一个新服务器,我想知道是否有更好的解决方案来解决这个问题。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(24)
回答问题的标题(但不是有关您所获得的输出的问题):
如果只是 Web 应用程序,则将以下文件夹从您的开发计算机复制到构建服务器可以修复此问题
根据构建中断的方式删除 x86。如果您有其他项目类型,您可能需要复制整个 msbuild 文件夹。
To answer the title of the question (but not the question about the output you're getting):
Copying the following folder from your dev machine to your build server fixes this if it's just web applications
Remove x86 according to how your build breaks. If you have other project types you will probably need to copy the entire msbuild folder.
解决方案是在构建服务器代理上安装可再发行软件包。它可以通过多种方式完成,下面介绍其中的 3 种。选择最适合您的一款。
使用带有 UI 的安装程序
这是原始答案
现在,在 2017 年,您可以使用 MSBuildTools 安装 WebApplication redists。只需转到此页面即可将下载 MSBuild 2017 工具,并在安装时单击
Web 开发构建工具
来安装这些目标:这将导致在
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications
中安装缺少的库默认情况下使用命令行
免责声明我还没有测试以下任何建议
正如@PaulHicks和@WaiHaLee在评论中建议的那样,它也可以从CLI以无头模式(无ui)安装,这可能实际上是解决删除服务器问题的更好方法。
解决方案 B - 以无头模式运行安装程序
注意,这与原始答案中建议使用的安装程序相同
The solution would be to install redistributable packages on build server agent. It can be accomplished multiple ways, out of which 3 are described below. Pick one that suits you best.
Use installer with UI
this is the original answer
Right now, in 2017, you can install WebApplication redists with MSBuildTools. Just go to this page that will download MSBuild 2017 Tools and while installation click
Web development build tools
to get these targets installed as well:This will lead to installing missing libraries in
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications
by defaultUse command line
disclaimer I haven't tested any of the following proposals
As @PaulHicks and @WaiHaLee suggested in comments, it can also be installed in headless mode (no ui) from CLI, that might actually be preferable way of solving the problem on remove server.
Solution B - run installer in headless mode
Notice, this is the same installer that has been proposed to be used in original answer
如果未安装 VS,则不支持构建和发布 WAP。话虽如此,如果您确实不想安装 VS,那么您需要复制
%ProgramFiles32%\MSBuild\Microsoft\
下的所有文件。您还需要安装Web 部署工具。我想就是这样。
Building and publishing WAPs is not supported if VS is not installed. With that said, if you really do not want to install VS then you will need to copy all the files under
%ProgramFiles32%\MSBuild\Microsoft\
.You will need to install the Web Deploy Tool as well. I think that is it.
UPD:从VS2017开始,构建工具中的工作负载完全消除了这个问题。请参阅@SOReader 答案。
如果您不想修改构建服务器上的任何内容,并且仍然希望项目直接在源代码控制之外构建,那么将所需的二进制文件置于源代码控制之下可能是个好主意。您需要将项目文件中的导入部分修改为如下所示:
第一行是从相对于解决方案目录的新位置的实际导入。第二个是原始行的关闭版本 (
Condition="false"
),它允许 Visual Studio 仍然将您的项目视为有效的 Web 应用程序项目(这就是 VS 的技巧) 2010 SP1 自行完成)。不要忘记将
C:\Program Files (x86)\Microsoft\VisualStudio\v10.0\WebApplications
复制到源代码管理下的BuildTargets
文件夹。UPD: as of VS2017, there is workload in Build Tools that eliminates this problem completely. See @SOReader answer.
If you'd prefer not to modify anything on build server, and you still want the project to build right out of source control, it might be a good idea to put the required binaries under source control. You'll need to modify the imports section in your project file to look like this:
The first line is the actual import from the new location that is relative to the solution directory. The second one is a turned-off version (
Condition="false"
) of the original line that allows for Visual Studio to still consider your project to be a valid Web Application Project (that's the trick that VS 2010 SP1 does itself).Don't forget to copy the
C:\Program Files (x86)\Microsoft\VisualStudio\v10.0\WebApplications
toBuildTargets
folder under your source control.您还可以使用 NuGet 包 MSBuild.Microsoft.VisualStudio.Web.targets,在 Visual Studio 项目中引用它们,然后按照 Andriy K 的建议更改引用。
You can also use the NuGet package MSBuild.Microsoft.VisualStudio.Web.targets, referencing them within your Visual Studio project(s), then change your references as Andriy K suggests.
基于 这篇文章在这里您可以简单地下载Microsoft Visual Studio 2010 Shell (集成)可再发行软件包 和目标已安装。
这避免了在生成服务器上安装 Visual Studio 的需要。
我现在刚刚尝试过,可以验证它是否有效:
之前:
安装后:
[正确构建]
显然,这是比在构建服务器上安装 Visual Studio 更好的解决方案。
Based on this post here you can simply download the Microsoft Visual Studio 2010 Shell (Integrated) Redistributable Package and the targets are installed.
This avoids the need to install Visual Studio on the build server.
I have just tried this out now, and can verify that it works:
Before:
After the install:
[Builds correctly]
This is a far better solution than installing Visual Studio on a build server, obviously.
如上所述,除了 "Microsoft Visual Studio 之外,还有最新的 Windows SDK Microsoft.WebApplication.targets 和 rel="noreferrer">"Microsoft Visual Studio Team System 2008 Database Edition GDR R2" for Microsoft.Data.Schema.SqlTasks.targets 应该可以减少安装 Visual Studio 2010 的需要。但是,安装 VS 2010 实际上可能是整体下载量减少,最终工作量也减少。
The latest Windows SDK, as mentioned above, in addition to the "Microsoft Visual Studio 2010 Shell (Integrated) Redistributable Package" for Microsoft.WebApplication.targets and "Microsoft Visual Studio Team System 2008 Database Edition GDR R2" for Microsoft.Data.Schema.SqlTasks.targets should alleviate the need to install Visual Studio 2010. However, installing VS 2010 maybe actually be less overall to download and less work in the end.
在构建/CI 服务器上构建时,通过指定
/p:VSToolsPath=''
完全关闭Microsoft.WebApplication.targets
的导入。从本质上讲,这将使以下行的条件为假:这是在 TeamCity 中完成的方式:
When building on the build/CI server, turn off the import of
Microsoft.WebApplication.targets
altogether by specifying/p:VSToolsPath=''
. This will, essentially, make the condition of the following line false:This is how it's done in TeamCity:
通过 NuGet & 添加依赖项设置构建参数
目标:构建代理无需更改/安装
我采用了混合方法 Lloyd 的 NuGet 方法在这里,它基于 Andrik 的提交二进制依赖项解决方案。
我希望能够添加新的构建代理,而不必使用此类项目预先配置它们。
[solution]\packages\MSBuild.Microsoft.VisualStudio.Web.targets.nn.nnn\tools\VSToolsPath\
在版本 7 中,我执行了以下操作。这可能没有必要,并且根据评论,现在肯定不需要。请参阅下面的评论。
env.VSToolsPath
添加构建参数,并将其设置为 VSToolsPath 文件夹;我使用 ..\packages\MSBuild.Microsoft.VisualStudio.Web.targets.11.0.2.1\tools\VSToolsPathAdd dependency through NuGet & set a Build Parameter
Goal: no changes / installs necessary to the build agents
I have taken a hybrid approach to the NuGet approach by Lloyd here, which was based off of the committing binary dependencies solution by Andrik.
The reason why is I want to be able to add new build agents without having to pre-configure them with items such as this.
[solution]\packages\MSBuild.Microsoft.VisualStudio.Web.targets.nn.n.n.n\tools\VSToolsPath\
In Version 7, I did the following. This may not have been necessary, and based on the comments is definitely not needed now. Please see the comments below.
env.VSToolsPath
and set it to the VSToolsPath folder; I used..\packages\MSBuild.Microsoft.VisualStudio.Web.targets.11.0.2.1\tools\VSToolsPath
如果将 Visual Studio 2012 迁移到 2013,则使用 edior 打开 *.csproj 项目文件。
并检查“Project”标签的 ToolsVersion 元素。
将其值从 4.0 更改为 12.0
From
<块引用>
至
<块引用>
至
或者如果您使用 msbuild 构建,则只需指定 VisualStudioVersion 属性
解决方案源
If you migrate Visual Studio 2012 to 2013, then open *.csproj project file with edior.
and check 'Project' tag's ToolsVersion element.
Change its value from 4.0 to 12.0
From
To
Or If you build with msbuild then just specify VisualStudioVersion property
Solution Source
新版本的 msbuild 似乎没有附带 Microsoft.WebApplication.targets。要修复此问题,您需要更新您的 csproj 文件,如下所示:
1) 编辑 Web 应用程序 csproj(右键单击)。在 csproj 底部找到有关构建工具的部分。看起来应该是这样的。
2) 您需要在 VisualStudioVersion 标记下方添加一行 VSToolsPath,使其看起来像这样
参考链接:
https://alastaircrabtree.com/cannot-open- vs-2015-web-project-in-vs-2017/
It seems the new version of msbuild does not ship with Microsoft.WebApplication.targets. To fix you need to update your csproj file as so:
1) Edit the web app csproj (right click). Find the section in the csproj towards the bottom concerning build tools. It should look like so.
2) You need to add one VSToolsPath line below the VisualStudioVersion tag so it looks like so
Reference link:
https://alastaircrabtree.com/cannot-open-vs-2015-web-project-in-vs-2017/
这就是您所需要的。只有103MB。不要安装所有内容
This is all you need. Only 103MB. Don't install everything
我在 MS 连接:
所以,这是我目前唯一的选择。
I have found this on MS connect:
So, this is the only option that I have for now.
任何人来到这里使用 Visual Studio 2017。我遇到了类似的问题,更新到 15.6.1 后无法编译项目。
我必须安装 MSBulild 工具,但错误仍然存在。
我可以通过将
v14.0
文件夹从C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio
复制到与相同的文件夹来解决此问题>v15.0
并解决了所有错误。现在我的文件夹结构如下所示,其中两个文件夹包含相同的内容。
Anyone coming here for Visual Studio 2017. I had the similar issue and couldn't compile the project after update to 15.6.1.
I had to install MSBulild tools but still the error was there.
I was able to fix the issue by copying the
v14.0
folder fromC:\Program Files (x86)\MSBuild\Microsoft\VisualStudio
to the same folder asv15.0
and that resolved all the errors.So now my folder structure looks like below, where both folders contain the same content.
如果您使用 MSBuild,就像构建服务器一样,对我有用的是:
更改以下内容:
更改为:
我的 Msbuild 命令是:
* "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"solution.sln /p:Configuration=Debug /p:Platform="Any CPU"*
希望这对某人有帮助。
If you are using MSBuild, as in the case of a build server, what worked for me is:
Change the following:
to:
My Msbuild command is:
*"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" solution.sln /p:Configuration=Debug /p:Platform="Any CPU"*
Hope this helps someone.
我的解决方案是这里几个答案的混合。
我检查了构建服务器,Windows7/NET4.0 SDK已经安装,所以我确实找到了路径:
但是,在这一行:
$(MSBuildExtensionsPath) 扩展为没有路径的 C:\Program Files\MSBuild。
因此,我所做的是使用以下命令创建符号链接:
这样 $(MSBuildExtensionsPath) 就会扩展为有效路径,无需进行任何更改在应用程序本身中,仅在构建服务器中(也许可以在每次构建时创建符号链接,以确保此步骤不会丢失并被“记录”)。
My solution is a mix of several answers here.
I checked the build server, and Windows7/NET4.0 SDK was already installed, so I did find the path:
However, on this line:
$(MSBuildExtensionsPath) expands to C:\Program Files\MSBuild which does not have the path.
Therefore what I did was to create a symlink, using this command:
This way the $(MSBuildExtensionsPath) expands to a valid path, and no changes are needed in the app itself, only in the build server (perhaps one could create the symlink every build, to make sure this step is not lost and is "documented").
我通过添加解决了这个问题
/p:VCTargetsPath="C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V120"
进入
构建>使用 MSBuild > 构建 Visual Studio 项目或解决方案命令行参数
I fixed this by adding
/p:VCTargetsPath="C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V120"
into
Build > Build a Visual Studio project or solution using MSBuild > Command Line Arguments
我尝试了很多解决方案,但最终这个答案对我有用: https://stackoverflow.com/a/19826448/431522
它基本上需要从 MSBuild 目录而不是 Visual Studio 目录调用 MSBuild。
我还将 MSBuild 目录添加到我的路径中,以使脚本更易于编码。
I tried a bunch of solutions, but in the end this answer worked for me: https://stackoverflow.com/a/19826448/431522
It basically entails calling MSBuild from the MSBuild directory, instead of the Visual Studio directory.
I also added the MSBuild directory to my path, to make the scripts easier to code.
我在 CI/CD 管道上构建 SQL Server 项目时遇到了这个问题。其实我本地也有这个问题,但没能解决。
对我有用的是使用 MSBuild SDK,它能够生成 SQL Server 数据-来自一组 SQL 脚本的层应用程序包 (
.dacpac
),这意味着创建一个新项目。但我想保留 SQL Server 项目,以便可以通过 Visual Studio 上的 SQL Server 对象资源管理器将其链接到实时数据库。我采取了以下步骤来启动并运行它:.sql
数据库脚本保留我的 SQL Server 项目。设置
.csproj
的内容如下:<块引用>
我选择 Sql140 作为 SQL Server 版本,因为我使用的是 SQL Server 2019。请查看此答案以了解详情到您正在使用的版本的映射。
在构建时忽略 SQL Server 项目,以便它停止在本地破坏(它确实在 Visual Studio 上构建,但在 VS Code 上失败)。
现在我们只需确保构建 SDK 项目时
.sql
文件位于该项目内即可。我通过 CI/CD 管道上的一个简单的 powershell 例程实现了这一点,该例程将文件从 SQL Server 项目复制到 SDK 项目:PS: 文件必须位于 SDK 项目中,无论是在根目录还是在某些文件夹,因此指向 SQL Server 项目中的
.sdk
文件的链接将不起作用。理论上,应该可以在预构建条件下复制这些文件,但由于某些不明原因,这对我不起作用。我还尝试将.sql
文件放在 SDK 项目上并将它们链接到 SQL Server 项目,但这很容易破坏与 SQL Server 对象资源管理器的链接,因此我决定将其删除为出色地。I was having this issue building a SQL Server project on a CI/CD pipeline. In fact, I was having it locally as well, and I did not manage to solve it.
What worked for me was using an MSBuild SDK, capable of producing a SQL Server Data-Tier Application package (
.dacpac
) from a set of SQL scripts, which implies creating a new project. But I wanted to keep the SQL Server project, so that I could link it to the live database through SQL Server Object Explorer on Visual Studio. I took the following steps to have this up and running:.sql
database scripts.Set the contents of the
.csproj
as follows:I have chosen Sql140 as the SQL Server version because I am using SQL Server 2019. Check this answer to find out the mapping to the version you are using.
Ignore the SQL Server project on build, so that it stops breaking locally (it does build on Visual Studio, but it fails on VS Code).
Now we just have to make sure the
.sql
files are inside the SDK project when it is built. I achieved that with a simple powershell routine on the CI/CD pipeline that would copy the files from the SQL Server project to the SDK project:PS: The files have to be physically in the SDK project, either in the root or on some folder, so links to the
.sdk
files in the SQL Server project won't work. In theory, it should be possible to copy these files with a pre-build condition, but for some obscure reason, this was not working for me. I tried also to have the.sql
files on the SDK project and link them to the SQL Server project, but that would easily break the link with the SQL Server Object Explorer, so I decided to drop this as well.如果您尝试使用 VSTS 部署项目,则问题可能与检查“托管 Windows 容器”选项而不是“托管 VS2017”(或 18 等)有关:
In case if you're trying to deploy a project using VSTS, then issue might be connected with checking "Hosted Windows Container" option instead of "Hosted VS2017"(or 18, etc.):
我通过在 docker 容器中运行构建来修复此问题,特别是 dotnet/framework/ sdk。它包括 VS 构建工具。
I fixed this by running the build in a docker container, specifically dotnet/framework/sdk. It includes the VS build tools.
创建一个新项目并复制设置可能会提供最好的指导。这就是我的样子
Creating a new project and copying over the settings should probably provide the best guidance in what to do. This is what it looks like on mine
就我而言,这只是一个端口块。
In my case, It was just a Port-Block.
-->
C:>msbuild "C:\\DotnetCi.sln" /p:Configuration= Release /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false
在此处输入图片说明
-->
C:>msbuild "C:\\DotnetCi.sln" /p:Configuration=Release /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false
enter image description here