尝试在构建服务器上构建我的项目会给我以下错误:
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.
几个月前,我在Build Server上安装了Visual Studio 2010,从而解决了这个问题。 但是现在我要从头开始安装新服务器,我想知道是否有更好的解决方案来解决此问题。
#1楼
根据此处的这篇文章,您可以简单地下载Microsoft Visual Studio 2010 Shell(集成)可再发行软件包,并安装目标。
这避免了在生成服务器上安装Visual Studio的需要。
我刚刚尝试了一下,可以验证它是否有效:
之前:
错误MSB4019:找不到导入的项目“ C:\\ Program Files(x86)\\ MSBuild \\ Microsoft \\ VisualStudio \\ v10.0 \\ WebApplications \\ Microsoft.WebApplication.targets”。 确认声明中的路径正确,并且文件在磁盘上。
安装后:
[正确构建]
显然,这比在构建服务器上安装Visual Studio更好。
#2楼
UPD:从VS2017开始,构建工具中的工作负载可以完全消除此问题。 参见@SOReader答案 。
如果您不希望在构建服务器上进行任何修改,并且仍然希望在源代码控制之外直接构建项目,则最好将所需的二进制文件置于源代码控制下。 您需要修改项目文件中的imports部分,如下所示:
<Import Project="$(SolutionDir)\BuildTargets\WebApplications\Microsoft.WebApplication.targets" />
<Import Condition="false" Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
第一行是相对于解决方案目录的新位置的实际导入。 第二个是原始行的关闭版本( Condition="false"
),该版本允许Visual Studio仍将您的项目视为有效的Web应用程序项目(这就是VS 2010 SP1本身的技巧)。
不要忘记将C:\\Program Files (x86)\\Microsoft\\VisualStudio\\v10.0\\WebApplications
复制到源代码管理下的BuildTargets
文件夹。
#3楼
您还可以使用NuGet包MSBuild.Microsoft.VisualStudio.Web.targets ,在Visual Studio项目中引用它们,然后按照Andriy K的建议更改引用。
#4楼
通过NuGet添加依赖项并设置构建参数
目标:无需对构建代理进行任何更改/安装
我在这里采用了Lloyd的NuGet方法的混合方法,该方法基于Andrik提交的二进制依赖项解决方案。
我之所以希望能够添加新的构建代理,而不必使用诸如此类的项目进行预配置,是因为。
- 在装有Visual Studio的计算机上,打开解决方案; 忽略该Web项目失败。
- 在NuGet程序包管理器中,添加MSBuild.Microsoft.VisualStudio.Web.targets ,如Lloyd所述。
- 这会将二进制文件解析为
[solution]\\packages\\MSBuild.Microsoft.VisualStudio.Web.targets.nn.nnn\\tools\\VSToolsPath\\
- 您可以将它们复制到引用文件夹并提交,
- 或者只是在它们所在的地方使用它们。 我选择了这个,但是稍后我将不得不处理路径中的版本号。
在版本7中,我执行了以下操作。 这可能不是必需的,并且现在绝对不需要基于注释。 请参阅下面的评论。
- 接下来,在TeamCity构建配置中,为
env.VSToolsPath
添加一个构建env.VSToolsPath
并将其设置到VSToolsPath文件夹中; 我使用了..\\packages\\MSBuild.Microsoft.VisualStudio.Web.targets.11.0.2.1\\tools\\VSToolsPath
#5楼
这就是您所需要的。 只有103MB。 不要安装所有内容

来源:oschina
链接:https://my.oschina.net/u/3797416/blog/3164082