DacFx icon indicating copy to clipboard operation
DacFx copied to clipboard

Unable to use NetCoreBuild in .sqlproj

Open ErikEJ opened this issue 2 years ago • 10 comments

  • SqlPackage or DacFx Version:
  • .NET Framework (Windows-only) or .NET Core:
  • Environment (local platform and source/target platforms):

Steps to Reproduce:

Convert a VS .sqplproj to SDK build.

Follow this from the readme (adding it to the first "PropertyGroup")

In Visual Studio, .NET Core targets can be used by default. Add this property to the sqlproj:

<NetCoreBuild>True</NetCoreBuild>

Excpected: project builds

Actual:

Severity Code Description Project File Line Suppression State Error Your project file doesn't list 'win' as a "RuntimeIdentifier". You should add 'win' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore. Database C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets 198

After manually deleting the bin and obj folders, I now get this error:

Severity Code Description Project File Line Suppression State Error 04062: The "SqlModelResolutionTask" task could not be loaded from the assembly C:\Users\Erik.nuget\packages\microsoft.build.sql\0.1.3-preview\Sdk..\tools\netstandard2.1\Microsoft.Data.Tools.Schema.Tasks.Sql.dll. Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. Database C:\Users\Erik.nuget\packages\microsoft.build.sql\0.1.3-preview\tools\netstandard2.1\Microsoft.Data.Tools.Schema.SqlTasks.targets 443

ErikEJ avatar Mar 06 '22 14:03 ErikEJ

@ErikEJ I'm able to reproduce this locally as well. I will investigate this further, but please note that the SDK-style sqlproj are not officially supported in SSDT/VS yet. Right now they're only supported in the Insiders build for Azure Data Studio.

zijchen avatar Mar 08 '22 20:03 zijchen

Thanks but if it does not work in VS, you should remove this from the docs until it does work at least.

ErikEJ avatar Mar 08 '22 20:03 ErikEJ

Thanks but if it does not work in VS, you should remove this from the docs until it does work at least.

Yes I'll update the README.

zijchen avatar Mar 08 '22 21:03 zijchen

@ErikEJ I was able to add the following properties into my sqlproj file to build both in VS as well as dotnet cli. Haven't tried SSDT:

    <NetCoreBuild Condition="'$(MSBuildRuntimeType)' != 'Core'">False</NetCoreBuild>
    <NetCoreBuild Condition="'$(MSBuildRuntimeType)' == 'Core'">True</NetCoreBuild>

I haven't tested extensively, so YMMV.

pvanhouten avatar May 13 '22 22:05 pvanhouten

@pvanhouten Simply using dotnet build works fine as well

ErikEJ avatar May 14 '22 06:05 ErikEJ

Unfortunately, dotnet build doesn't work for me without specifying -p:NetCoreBuild=true as an argument. It fails with error MSB4019. Long story short, in my project, I don't have the ability to add that argument to dotnet build and it needs to be embedded in the sqlproj file. Adding those conditions to that property allows me to use both VS and dotnet build without having to add that argument.

pvanhouten avatar May 14 '22 13:05 pvanhouten

@pvanhouten

Unfortunately, dotnet build doesn't work for me without specifying -p:NetCoreBuild=true as an argument.

Correct, as stated in my blog post - thanks for the tip!

ErikEJ avatar May 14 '22 13:05 ErikEJ

We could kind of fix this by using the following

    <NetCoreBuild Condition=" '$(BuildingInsideVisualStudio)' != 'true'">true</NetCoreBuild>

This disables it while running in Visual Studio but has it enabled when building via dotnet from the command-line.

pfeigl avatar Aug 26 '22 09:08 pfeigl

@pfeigl How does that work for a msbuild based solution build?

ErikEJ avatar Aug 26 '22 10:08 ErikEJ

Oh, didn't actually test that, I was happy after building in VS and via dotnet build worked. After trying it now - it actually does not work and the solution from @pvanhouten is superior to what we did. (which I somehow missed tbh).

pfeigl avatar Aug 26 '22 12:08 pfeigl