Cake.SqlServer icon indicating copy to clipboard operation
Cake.SqlServer copied to clipboard

Cake.SqlServer doesn't work right out of the box

Open rodrigoramos opened this issue 4 years ago • 3 comments

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

  1. In a new folder, create dotnet tool manifest:
    dotnet new tool-manifest
    
  2. Install cake tool
    dotnet tool install Cake.Tool --version 1.2.0
    
  3. 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);
    
  4. 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

rodrigoramos avatar Oct 07 '21 13:10 rodrigoramos

Hi, thanks for reporting - I will take a look at this

AdaskoTheBeAsT avatar Oct 13 '21 18:10 AdaskoTheBeAsT

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"

AdaskoTheBeAsT avatar Oct 13 '21 19:10 AdaskoTheBeAsT

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

Roemer avatar Jan 17 '22 13:01 Roemer