Cake.SqlServer doesn't work right out of the box
Description
Creating a new cake script using dotnet tool and try to use any alias from Cake.SqlServer, we get the following error:
(3292,5): error CS0012: The type 'SqlConnection' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'.
Steps to Reproduce
Steps
- In a new folder, create dotnet tool manifest:
dotnet new tool-manifest - Install cake tool
dotnet tool install Cake.Tool --version 1.2.0 - Create a build.cake script with the following contents:
#addin "Cake.SqlServer&version=3.0.0" var target = Argument("target", "Test"); Task("Test") .Does(() => { const string connStr = "<your connection string>"; CreateDatabaseIfNotExists(connStr, "EXAMPLE_DATABASE"); }); RunTarget(target); - Run cake script:
dotnet cake
Expected Result
The script should run without issues and create the database "EXAMPLE_DATABASE"
Actual Result
The following output (with errors) is presented:
Could not load /tmp/fk/tools/Addins/Cake.SqlServer.3.0.0/lib/net5.0/Cake.SqlServer.dll (missing Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5))
(3292,5): error CS0012: The type 'SqlConnection' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'.
Error: Error(s) occurred when compiling build script:
(3292,5): error CS0012: The type 'SqlConnection' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'.
Environment
SO: Linux Manjaro Dotnet SDK: 5.0.400 Dotnet Runtime: - Microsoft.NETCore.App 5.0.9 - Microsoft.AspNetCore.App 5.0.9
Hi, thanks for reporting - I will take a look at this
For now I have only workaround please add in the top of the script #addin "Cake.SqlServer&version=3.0.0&loaddependencies=true"
or add this - but when using this other references can be needed #addin "Microsoft.Data.SqlClient&version=3.0.0" #addin "System.Configuration.ConfigurationManager&version=4.7.0" #addin "Microsoft.Identity.Client&version=4.22.0" #addin "Azure.Identity&version=1.3.0" #addin "Azure.Core&version=1.6.0" #addin "Microsoft.Identity.Client.Extensions.Msal&version=2.16.5" #addin "Microsoft.Bcl.AsyncInterfaces&version=1.0.0"
Unfortunately that does not work for us. The only workaround that worked for us is by adding:
#addin nuget:?package=System.Data.SqlClient&version=4.8.3