在生成服务器上找不到 Microsoft.WebApplication.targets。你的解决方案是什么?

发布于 2024-09-28 15:42:42 字数 989 浏览 4 评论 0 原文

尝试在生成服务器上生成我的项目时出现以下错误:

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 解决了这个问题。但现在我正在从头开始设置一个新服务器,我想知道是否有更好的解决方案来解决这个问题。

Trying to build my project on the build server gives me the following error:

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.

I solved this problem a few months ago, with installing Visual Studio 2010 on the Build Server. But now I'm setup a new server from scratch, and I want to know if there any better solution to solve this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(24

遥远的她 2024-10-05 15:42:42

回答问题的标题(但不是有关您所获得的输出的问题):

如果只是 Web 应用程序,则将以下文件夹从您的开发计算机复制到构建服务器可以修复此问题

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

根据构建中断的方式删除 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

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

Remove x86 according to how your build breaks. If you have other project types you will probably need to copy the entire msbuild folder.

闻呓 2024-10-05 15:42:42

解决方案是在构建服务器代理上安装可再发行软件包。它可以通过多种方式完成,下面介绍其中的 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)安装,这可能实际上是解决删除服务器问题的更好方法。

  • 解决方案 A - 使用包管理器 (choco)
choco install visualstudio2017-workload-webbuildtools
  • 解决方案 B - 以无头模式运行安装程序

    注意,这与原始答案中建议使用的安装程序相同

vs_BuildTools.exe --add Microsoft.VisualStudio.Workload.WebBuildTools --passive

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:
enter image description here

This will lead to installing missing libraries in C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications by default

Use 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 A - using package manager (choco)
choco install visualstudio2017-workload-webbuildtools
  • Solution B - run installer in headless mode

    Notice, this is the same installer that has been proposed to be used in original answer

vs_BuildTools.exe --add Microsoft.VisualStudio.Workload.WebBuildTools --passive
决绝 2024-10-05 15:42:42

如果未安装 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.

情仇皆在手 2024-10-05 15:42:42

UPD:从VS2017开始,构建工具中的工作负载完全消除了这个问题。请参阅@SOReader 答案

如果您不想修改构建服务器上的任何内容,并且仍然希望项目直接在源代码控制之外构建,那么将所需的二进制文件置于源代码控制之下可能是个好主意。您需要将项目文件中的导入部分修改为如下所示:

<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 文件夹。

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:

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

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 to BuildTargets folder under your source control.

小巷里的女流氓 2024-10-05 15:42:42

您还可以使用 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.

临风闻羌笛 2024-10-05 15:42:42

基于 这篇文章在这里您可以简单地下载Microsoft Visual Studio 2010 Shell (集成)可再发行软件包 和目标已安装。

这避免了在生成服务器上安装 Visual Studio 的需要。

我现在刚刚尝试过,可以验证它是否有效:

之前:

错误 MSB4019:导入的项目“C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"
没有找到。确认声明中的路径是
正确,并且该文件存在于磁盘上。

安装后:

[正确构建]

显然,这是比在构建服务器上安装 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:

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 declaration is
correct, and that the file exists on disk.

After the install:

[Builds correctly]

This is a far better solution than installing Visual Studio on a build server, obviously.

薔薇婲 2024-10-05 15:42:42

如上所述,除了 "Microsoft Visual Studio 之外,还有最新的 Windows SDK Microsoft.WebApplication.targets 和 rel="noreferrer">"Microsoft Visual Studio Team System 2008 Database Edition GDR R2" for Microsoft.Data.Schema.SqlTask​​s.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.

稚气少女 2024-10-05 15:42:42

在构建/CI 服务器上构建时,通过指定 /p:VSToolsPath='' 完全关闭 Microsoft.WebApplication.targets 的导入。从本质上讲,这将使以下行的条件为假:

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

这是在 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:

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

This is how it's done in TeamCity:

enter image description here

灼疼热情 2024-10-05 15:42:42

通过 NuGet & 添加依赖项设置构建参数

目标:构建代理无需更改/安装

我采用了混合方法 Lloyd 的 NuGet 方法在这里,它基于 Andrik 的提交二进制依赖项解决方案。

我希望能够添加新的构建代理,而不必使用此类项目预先配置它们。

  1. 在装有 Visual Studio 的机器上,打开解决方案;忽略 Web 项目失败。
  2. 在 NuGet 包管理器中,添加 MSBuild.Microsoft.VisualStudio.Web.targets ,正如劳埃德提到的。
  3. 这会将二进制文件解析为 [solution]\packages\MSBuild.Microsoft.VisualStudio.Web.targets.nn.nnn\tools\VSToolsPath\
    1. 您可以将它们复制到参考文件夹中。提交,
    2. 或者只是在它们所在的地方使用它们。我选择了这个,但稍后我必须处理路径中的版本号。

在版本 7 中,我执行了以下操作。这可能没有必要,并且根据评论,现在肯定不需要。请参阅下面的评论。

  1. 接下来,在 TeamCity 构建配置中,为 env.VSToolsPath 添加构建参数,并将其设置为 VSToolsPath 文件夹;我使用 ..\packages\MSBuild.Microsoft.VisualStudio.Web.targets.11.0.2.1\tools\VSToolsPath

Add 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.

  1. On a machine with Visual Studio, Open the solution; ignore that the web project fails.
  2. In the NuGet package manager, add MSBuild.Microsoft.VisualStudio.Web.targets, as Lloyd mentioned.
  3. This will resolve the binaries to [solution]\packages\MSBuild.Microsoft.VisualStudio.Web.targets.nn.n.n.n\tools\VSToolsPath\
    1. You can copy these to a references folder & commit,
    2. Or just use them where they are at. I chose this, but I'm going to have to deal with the version number in the path later.

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.

  1. Next, in your TeamCity build configuration, add a build Paramenter for env.VSToolsPath and set it to the VSToolsPath folder; I used ..\packages\MSBuild.Microsoft.VisualStudio.Web.targets.11.0.2.1\tools\VSToolsPath
顾挽 2024-10-05 15:42:42

如果将 Visual Studio 2012 迁移到 2013,则使用 edior 打开 *.csproj 项目文件。
并检查“Project”标签的 ToolsVersion 元素。

将其值从 4.0 更改为 12.0

  • From

    <块引用>

    
    <项目工具版本=“4.0”...
    
  • <块引用>

    
    <项目工具版本=“12.0”...
    

或者如果您使用 msbuild 构建,则只需指定 VisualStudioVersion 属性

msbuild /p:VisualStudioVersion=12.0

解决方案源

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

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" ...
    
  • To

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="12.0" ...
    

Or If you build with msbuild then just specify VisualStudioVersion property

msbuild /p:VisualStudioVersion=12.0

Solution Source

半边脸i 2024-10-05 15:42:42

新版本的 msbuild 似乎没有附带 Microsoft.WebApplication.targets。要修复此问题,您需要更新您的 csproj 文件,如下所示:

1) 编辑 Web 应用程序 csproj(右键单击)。在 csproj 底部找到有关构建工具的部分。看起来应该是这样的。

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

2) 您需要在 VisualStudioVersion 标记下方添加一行 VSToolsPath,使其看起来像这样

<PropertyGroup>  
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
  <!--Add the below line to fix the project loading in VS 2017 -->
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  <!--End -->
</PropertyGroup>  
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />  
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />  
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />  

参考链接:
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.

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

2) You need to add one VSToolsPath line below the VisualStudioVersion tag so it looks like so

<PropertyGroup>  
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
  <!--Add the below line to fix the project loading in VS 2017 -->
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  <!--End -->
</PropertyGroup>  
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />  
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />  
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />  

Reference link:
https://alastaircrabtree.com/cannot-open-vs-2015-web-project-in-vs-2017/

慕烟庭风 2024-10-05 15:42:42

这就是您所需要的。只有103MB。不要安装所有内容

在此处输入图像描述

This is all you need. Only 103MB. Don't install everything

enter image description here

酸甜透明夹心 2024-10-05 15:42:42

我在 MS 连接

是的,您需要安装 Visual Studio
2010 年在您的构建机器上构建
数据库项目。这样做的话
不需要额外的许可证
Visual Studio。

所以,这是我目前唯一的选择。

I have found this on MS connect:

Yes, you need to install Visual Studio
2010 on your build machine to build
database projects. Doing so does
not require an additional license of
Visual Studio.

So, this is the only option that I have for now.

凝望流年 2024-10-05 15:42:42

任何人来到这里使用 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 from C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio to the same folder as v15.0 and that resolved all the errors.
So now my folder structure looks like below, where both folders contain the same content.

enter image description here

谁对谁错谁最难过 2024-10-05 15:42:42

如果您使用 MSBuild,就像构建服务器一样,对我有用的是:

更改以下内容:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

更改为:

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

我的 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:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

to:

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

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.

半衬遮猫 2024-10-05 15:42:42

我的解决方案是这里几个答案的混合。

我检查了构建服务器,Windows7/NET4.0 SDK已经安装,所以我确实找到了路径:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets`

但是,在这一行:

<导入项目=“$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets”/>

$(MSBuildExtensionsPath) 扩展为没有路径的 C:\Program Files\MSBuild

因此,我所做的是使用以下命令创建符号链接:

mklink /J“C:\Program Files\MSBuild\Microsoft\VisualStudio”“C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio”

这样 $(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:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets`

However, on this line:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />

$(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:

mklink /J "C:\Program Files\MSBuild\Microsoft\VisualStudio" "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio"

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").

黯然#的苍凉 2024-10-05 15:42:42

我通过添加解决了这个问题
/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

岁吢 2024-10-05 15:42:42

我尝试了很多解决方案,但最终这个答案对我有用: 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.

摘星┃星的人 2024-10-05 15:42:42

我在 CI/CD 管道上构建 SQL Server 项目时遇到了这个问题。其实我本地也有这个问题,但没能解决。

对我有用的是使用 MSBuild SDK,它能够生成 SQL Server 数据-来自一组 SQL 脚本的层应用程序包 (.dacpac),这意味着创建一个新项目。但我想保留 SQL Server 项目,以便可以通过 Visual Studio 上的 SQL Server 对象资源管理器将其链接到实时数据库。我采取了以下步骤来启动并运行它:

  1. 使用 .sql 数据库脚本保留我的 SQL Server 项目。
  2. 创建一个 .NET Standard 2.0 类库项目,确保目标框架是 .NET Standard 2.0,按照上述链接中的指南。
  3. 设置.csproj的内容如下:

    <块引用>

    
    <项目 Sdk="MSBuild.Sdk.SqlProj/1.0.0">
      <财产组>
        Sql140
        netstandard2.0
      
    
    
  4. 我选择 Sql140 作为 SQL Server 版本,因为我使用的是 SQL Server 2019。请查看此答案以了解详情到您正在使用的版本的映射。

  5. 在构建时忽略 SQL Server 项目,以便它停止在本地破坏(它确实在 Visual Studio 上构建,但在 VS Code 上失败)。

  6. 现在我们只需确保构建 SDK 项目时 .sql 文件位于该项目内即可。我通过 CI/CD 管道上的一个简单的 powershell 例程实现了这一点,该例程将文件从 SQL Server 项目复制到 SDK 项目:

复制项目-路径“Path.To.The.Database.Project\dbo\Tables\*”
- 目标(新项目 - 名称“dbo\Tables” - 类型目录 - 路径“Path.To.The.DatabaseSDK.Project\”)

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:

  1. Kept my SQL Server project with the .sql database scripts.
  2. Created a .NET Standard 2.0 class library project, making sure that the target framework was .NET Standard 2.0, as per the guidelines in the above link.
  3. Set the contents of the .csproj as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <Project Sdk="MSBuild.Sdk.SqlProj/1.0.0">
      <PropertyGroup>
        <SqlServerVersion>Sql140</SqlServerVersion>
        <TargetFramework>netstandard2.0</TargetFramework>
      </PropertyGroup>
    </Project>
    
  4. 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.

  5. 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).

  6. 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:

Copy-Item -Path "Path.To.The.Database.Project\dbo\Tables\*"
-Destination (New-item -Name "dbo\Tables" -Type Directory -Path "Path.To.The.DatabaseSDK.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.

孤者何惧 2024-10-05 15:42:42

如果您尝试使用 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.):

enter image description here

找回味觉 2024-10-05 15:42:42

我通过在 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.

×眷恋的温暖 2024-10-05 15:42:42

创建一个新项目并复制设置可能会提供最好的指导。这就是我的样子

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

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

  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
撕心裂肺的伤痛 2024-10-05 15:42:42

就我而言,这只是一个端口块。

In my case, It was just a Port-Block.

时光磨忆 2024-10-05 15:42:42
  • 安装Microsoft的MSBuild工具后,在环境变量中定义MSBuild路径,以便可以从任何路径运行它。
  • 在任何记事本编辑器(例如 notepad++)中编辑 .csproj 文件,并注释检查
  • 以下元素,

    -->

    • 确保仅使用导入一次,选择有效的。
    • 确保驱动器上存在以下文件夹“C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0”或“C:\Program Files”中 MSBuild 目标引用的任何版本(x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets"
    • 从命令提示符处运行以下命令来检查

C:>msbuild "C:\\DotnetCi.sln" /p:Configuration= Release /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false

  • After installation of MSBuild tools from Microsoft, define the MSBuild path in the environment variable, so that it can be run from any path.
  • Edit the .csproj file in any notepad editor such as notepad++, and comment the
  • Check for the following elements,

    -->

    • Make sure you use import only once, choose whichever works.
    • Make sure you have the following folder exists on the drive, "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0" or whichever version is referenced by MSBuild target at "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets"
    • From the command prompt, run the following command, to check

C:>msbuild "C:\\DotnetCi.sln" /p:Configuration=Release /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文