简体   繁体   English

如何使用dotnet(.NET Core)打包包含sql项目的sln文件?

[英]How to use dotnet (.NET Core) to pack a sln file that contains a sql project?

I have a nothing-special .NET Core solution, lets call it Application.sln , and it contains 12 C# projects, and 1 SQL project. 我有一个没什么特别的.NET Core解决方案,我们称之为Application.sln ,它包含12个C#项目和1个SQL项目。 In Visual Studio 2017, I have no issue building all the projects, but when I head to the command line to package up the projects using dotnet pack Application.sln --no-build , I immediately run into an issue with the sql project. 在Visual Studio 2017中,我没有构建所有项目的问题,但是当我前往命令行使用dotnet pack Application.sln --no-build项目时,我立即遇到了sql项目的问题。 Here is the error: 这是错误:

error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.1.0\Microsoft\VisualStudio\v14.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk

After deciphering that, I found out that the first part, C:\\Program Files\\dotnet\\sdk\\1.1.0 comes from me using dotnet instead of msbuild to package up the solution, and since SSDT cannot be installed into the dotnet folder, this will fail. 解读之后,我发现第一部分C:\\Program Files\\dotnet\\sdk\\1.1.0来自我使用dotnet而不是msbuild打包解决方案,而且由于SSDT无法安装到dotnet文件夹中,这会失败。

Preferably, I would like it to ignore the .sqlproj project and only pack the .csproj projects as I will be handling the sql projects separately afterwards, but I do not see any way to do that. 最好,我希望它忽略.sqlproj项目,只包装.csproj项目,因为我将在之后单独处理sql项目,但我没有看到任何方法这样做。 Is there a way? 有办法吗? It does not appear that I can use MSBuild style wild cards as a parameter to dotnet pack (***.csproj) as that throws a separate error. 似乎我不能使用MSBuild样式的通配符作为dotnet pack (***。csproj)的参数,因为它会抛出一个单独的错误。

I have tried using msbuild /t:pack but that gives me other issues (it says the target "pack" does not exist in the project). 我尝试过使用msbuild / t:pack,但这给了我其他问题(它说项目中不存在目标“pack”)。

Does anyone have any suggestions for me? 有人对我有什么建议吗? If it helps, I am wanting to do this through TeamCity, but all of these issues exist on my development machine as well. 如果它有帮助,我想通过TeamCity这样做,但所有这些问题也存在于我的开发机器上。

First, if you want to use the dotnet tools, you will need to create a second solution that contains only the c# projects. 首先,如果要使用dotnet工具,则需要创建仅包含c#项目的第二个解决方案。 If you don't want to do this, you can always use the msbuild commands directly from the VS 2017 developer command prompt ( dotnet restore => msbuild /t:Restore etc.) 如果您不想这样做,您可以直接从VS 2017开发人员命令提示符( dotnet restore => msbuild /t:Restore等)直接使用msbuild命令。

The Pack target is only available for projects with integrated NuGet package support, which comes through using the Microsoft.NET.Sdk SDK ("new" csproj format) or using the NuGet.Build.Tasks.Pack nuget package in projects that are compatible with it. Pack目标仅适用于具有集成NuGet包支持的项目,该项目通过使用Microsoft.NET.Sdk SDK(“新”csproj格式)或在兼容的项目中使用NuGet.Build.Tasks.Pack nuget包来实现。它。

If you want to call dotnet pack / msbuild /t:Pack on a solution without creating a second solution without the sql projects, all projects must contain a pack target. 如果要在不创建没有sql项目的第二个解决方案的情况下调用dotnet pack / msbuild /t:Pack解决方案,则所有项目都必须包含一个包目标。

An easy way to do that is to create a Directory.Build.props file next to the solution with the following contents: 一种简单的方法是使用以下内容在解决方案旁边创建Directory.Build.props文件:

<Project>
  <Target Name="Pack" />
</Project>

This file will be automatically imported at the beginning of all projects in the directory hierarchy and define an empty Pack target in them. 此文件将在目录层次结构中的所有项目的开头自动导入,并在其中定义一个空的Pack目标。 Projects using the .NET SDK will then overwrite this target with the actual NuGet pack targets. 然后,使用.NET SDK的项目将使用实际的NuGet包目标覆盖此目标。 So msbuild /t:Pack will call this empty target on the SQL project and the original NuGet Pack target on the c# projects. 因此, msbuild /t:Pack将在SQL项目上调用此空目标,并在c#项目上调用原始NuGet Pack目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM