Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I have tried using msbuild /t:pack but that gives me other issues (it says the target "pack" does not exist in the project).

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.

like image 967
B. Witter Avatar asked Aug 27 '17 20:08

B. Witter


People also ask

How do I add a project to a solution file?

To add an item to a solution, on the context (right-click) menu of the solution node in Solution Explorer, select Add > New Item, or Add > Existing Item. A solution file is a structure for organizing projects in Visual Studio.

How do I add a project reference in net core project?

One method of adding references to your library is by typing it directly in the project. json file. As you can see that we have added some references under the dependencies section as shown in the following code. Let us now save this file and you will see that references are added to your library now.

How do I read .sln files?

A file with . SLN extension represents a Visual Studio solution file that keeps information about the organization of projects in a solution file. The contents of such a solution file are written in plain text inside the file and can be observed/edited by opening the file in any text editor.


1 Answers

First, if you want to use the dotnet tools, you will need to create a second solution that contains only the c# projects. 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.)

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.

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.

An easy way to do that is to create a Directory.Build.props file next to the solution with the following contents:

<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. Projects using the .NET SDK will then overwrite this target with the actual NuGet pack targets. So msbuild /t:Pack will call this empty target on the SQL project and the original NuGet Pack target on the c# projects.

like image 106
Martin Ullrich Avatar answered Oct 19 '22 19:10

Martin Ullrich