cake icon indicating copy to clipboard operation
cake copied to clipboard

It's not possible to use Microsoft.Data.SqlClient

Open rodrigoramos opened this issue 2 years ago • 13 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched issues to ensure it has not already been reported

Cake runner

Cake .NET Tool, Cake runner for .NET Core

Cake version

1.2.0

Operating system

Linux

Operating system architecture

64-Bit

CI Server

No response

What are you seeing?

It's not possible to use Microsoft.Data.SqlClient nuget on cake script. Some addins like Cake.SqlServer and Cake.SqlTools cannot be used.

The following error is showed:

An error occurred when executing task 'Test'.
Error: One or more errors occurred. (Strings.PlatformNotSupported_DataSqlClient)
	Strings.PlatformNotSupported_DataSqlClient

What is expected?

I expect to be able to use this package. Like a I said before, it's referenced by addins which handles databases.

In the same machine/environment, we create a new console application, adding the same package as reference and running this application, it'll work as expected.

Steps to Reproduce

  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 "nuget:?package=Microsoft.Data.SqlClient&version=3.0.0"
    
    var target = Argument("target", "Test");
    
    Task("Test")
      .Does(() =>
      {
          const string connStr = "<your connection string>";
    
          var conn = new Microsoft.Data.SqlClient.SqlConnection(connStr);
    
      });
    
     RunTarget(target);
    
  4. Run cake script:
    dotnet cake
    

Output log

Looking for modules...
No modules found to install.
Module directory does not exist.
Analyzing build script...
[30;1mAnalyzing [0m[37m/tmp/fk/build.cake[0m[30;1m...[0m
Processing build script...
Installing addins...
Resolving assembly 'System.Private.Uri.resources, Version=4.0.6.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a' using runtime installed at '/home/rramos/.dotnet/shared/Microsoft.NETCore.App/3.1.18/'...
Exception occurred while resolving assembly System.Private.Uri.resources: Could not load file or assembly 'System.Private.Uri.resources, Version=4.0.6.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Trying to resolve assembly System.Private.Uri.resources as 'System.Private.Uri, Version=4.0.6.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a'...
Assembly System.Private.Uri resolved as 'System.Private.Uri, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' (file location: '/home/rramos/.dotnet/shared/Microsoft.NETCore.App/3.1.18/System.Private.Uri.dll')
[30;1mThe addin [0m[37mMicrosoft.Data.SqlClient[0m[30;1m will reference [0m[37mMicrosoft.Data.SqlClient.dll[0m[30;1m.[0m
[30;1mVerifying assembly '[0m[37mMicrosoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5[0m[30;1m'.[0m
[30;1mAdding assembly reference to [0m[37mSystem.Private.CoreLib.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mSystem.Linq.Expressions.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mMicrosoft.CSharp.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mCake.Core.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mCake.Common.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mSpectre.Console.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mnetstandard.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mMicrosoft.Win32.Registry.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mSystem.Memory.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mWcwidth.dll[0m[30;1m...[0m
[30;1mAdding assembly reference to [0m[37mMicrosoft.Data.SqlClient.dll[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.AppVeyor[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.AppVeyor.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.AzurePipelines[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.AzurePipelines.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.Bamboo[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.Bamboo.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.BitbucketPipelines[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.BitbucketPipelines.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.Bitrise[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.Bitrise.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.ContinuaCI[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.ContinuaCI.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.GitHubActions[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.GitHubActions.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.GitLabCI[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.GitLabCI.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.GoCD[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.GoCD.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.Jenkins[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.Jenkins.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.MyGet[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.TeamCity[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.TravisCI[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Build.TravisCI.Data[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Diagnostics[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.IO[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.IO.Paths[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Net[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Security[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Solution[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Solution.Project[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Solution.Project.Properties[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Solution.Project.XmlDoc[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Text[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Cake[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.ApiKey[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Config[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Download[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Features[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Install[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.New[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Pack[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Pin[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Push[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Sources[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Uninstall[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Chocolatey.Upgrade[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotCover[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotCover.Analyse[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotCover.Cover[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotCover.Merge[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotCover.Report[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.Build[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.BuildServer[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.Clean[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.Execute[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.MSBuild[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.NuGet.Delete[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.NuGet.Push[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.NuGet.Source[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.Pack[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.Publish[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.Restore[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.Run[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.Test[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.Tool[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DotNetCore.VSTest[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.DupFinder[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Fixie[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitLink[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseManager[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseManager.AddAssets[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseManager.Close[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseManager.Create[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseManager.Discard[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseManager.Export[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseManager.Label[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseManager.Open[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseManager.Publish[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitReleaseNotes[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.GitVersion[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.ILMerge[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.ILRepack[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.InnoSetup[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.InspectCode[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.MSBuild[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.MSpec[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.MSTest[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NSIS[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.Add[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.Delete[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.Init[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.Install[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.List[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.Pack[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.Push[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.Restore[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.SetApiKey[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.SetProxy[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.Sources[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NuGet.Update[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.NUnit[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.OctopusDeploy[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.OpenCover[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.ReportGenerator[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.ReportUnit[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.Roundhouse[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.SignTool[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.SpecFlow[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.SpecFlow.StepDefinitionReport[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.SpecFlow.TestExecutionReport[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.TextTransform[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.VSTest[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.VSWhere[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.VSWhere.All[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.VSWhere.Latest[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.VSWhere.Legacy[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.VSWhere.Product[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.WiX[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.WiX.Heat[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.XBuild[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Tools.XUnit[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Common.Xml[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Core[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Core.Diagnostics[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Core.IO[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mCake.Core.Scripting[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mSystem[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mSystem.Collections.Generic[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mSystem.IO[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mSystem.Linq[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mSystem.Text[0m[30;1m...[0m
[30;1mImporting namespace [0m[37mSystem.Threading.Tasks[0m[30;1m...[0m
Compiling build script...

========================================
Test
========================================
[37mExecuting task: [0m[37;1mTest[0m
[41m[37;1mAn error occurred when executing task '[0m[41;1m[37;1mTest[0m[41m[37;1m'.[0m
[41m[37;1mError: [0m[41;1m[37;1mSystem.AggregateException: One or more errors occurred. (Strings.PlatformNotSupported_DataSqlClient)
 ---> System.PlatformNotSupportedException: Strings.PlatformNotSupported_DataSqlClient
   at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString) in /_/artifacts/Project/obj/Release.AnyCPU/Microsoft.Data.SqlClient/netcore/netcoreapp3.1/Microsoft.Data.SqlClient.notsupported.cs:line 386
   at Submission#0.<>c.<<Initialize>>b__0_0()
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass31_0.<Does>b__0(ICakeContext _) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 26
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass34_0.<Does>b__0(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 82
   at Cake.Core.CakeTask.Execute(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTask.cs:line 119
   at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context) in C:\projects\cake\src\Cake.Core\DefaultExecutionStrategy.cs:line 74
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 278
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 303
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 311
   at Cake.Core.CakeEngine.RunTask(ICakeContext context, IExecutionStrategy strategy, CakeTask task, String target, Stopwatch stopWatch, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 226
   at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 189
   at Cake.Cli.BuildScriptHost`1.RunTargetAsync(String target) in C:\projects\cake\src\Cake.Cli\Hosts\BuildScriptHost.cs:line 73
   at Cake.Core.Scripting.ScriptHost.RunTarget(String target) in C:\projects\cake\src\Cake.Core\Scripting\ScriptHost.cs:line 105
   at Submission#0.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Cake.Infrastructure.Scripting.RoslynScriptSession.Execute(Script script) in C:\projects\cake\src\Cake\Infrastructure\Scripting\RoslynScriptSession.cs:line 167
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 173
   at Cake.Features.Building.BuildFeature.RunCore(IRemainingArguments arguments, BuildFeatureSettings settings) in C:\projects\cake\src\Cake\Features\Building\BuildFeature.cs:line 99
   at Cake.Features.Building.BuildFeature.Run(IRemainingArguments arguments, BuildFeatureSettings settings) in C:\projects\cake\src\Cake\Features\Building\BuildFeature.cs:line 49
   at Cake.Commands.DefaultCommand.Execute(CommandContext context, DefaultCommandSettings settings) in C:\projects\cake\src\Cake\Commands\DefaultCommand.cs:line 72[0m

rodrigoramos avatar Oct 07 '21 15:10 rodrigoramos

Possibly related from Microsoft's SQL Client FAQ (emphasis mine):

Why do I get a PlatformNotSupported exception when my application hits a SqlClient method? The Microsoft.Data.SqlClient NuGet package includes a number of DLLs supporting different .NET targets and different runtime platforms. If you are getting a PlatformNotSupported Exception when you don't think you should be, it ultimately means your application is not loading the appropriate DLL. There could be a number of reasons for this. The NuGet package structure and infrastructure around referencing and loading referenced NuGet packages includes logic that allows a package to contain multiple DLLs which implement support for different .NET and platform targets. Meaning a different DLL for .NET Framework, .NET Core, .NET Standard, Windows, Linux, etc. The NuGet infrastructure will automatically reference and load the appropriate DLL based on your application's needs.

If your application loads a DLL from a NuGet package directly, it bypasses all this logic and probably loads the incorrect DLL. The DLL in the NuGet package under lib/netstandard2.0/Microsoft.Data.SqlClient.dll is basically the fallback DLL for any unsupported target and simply throws the PlatformNotSupported exception for any call. This is a nicer exception than what you would otherwise get when running on a platform that does not have a DLL built for it. Ultimately, you want to use the NuGet package reference infrastructure or you would have to implement all this target framework and platform support logic yourself when determining which DLL to load.

Additionally, the NuGet package contains all the dependency information for the SqlClient library and facilitates the downloading and referencing of dependencies. If you reference and load an individual DLL manually, it is up to you to ensure all dependencies are also available to the SqlClient library.

Needs further investigation, but the above suggests that Cake might be loading the netstandard2.0 assembly rather than the assembly for the corresponding TFM of the Cake runner e.g. netcoreapp3.1

augustoproiete avatar Oct 07 '21 15:10 augustoproiete

Reproducible on OSX using the script above:

image

augustoproiete avatar Oct 07 '21 16:10 augustoproiete

Hi,

I will take a look at this and get back to you

AdaskoTheBeAsT avatar Nov 15 '21 07:11 AdaskoTheBeAsT

indeed there is problem with OSX - I try to find some help - I do not know if it is not connected with the fact that Microsoft.Data.SqlClient do not contain only folder for unix and not for osx - if Cake somewhat does not influence there in WSL2 Ubuntu 20.04 it looks like below

image

AdaskoTheBeAsT avatar Nov 16 '21 16:11 AdaskoTheBeAsT

on OSX I receive for simplified sample image

AdaskoTheBeAsT avatar Nov 16 '21 16:11 AdaskoTheBeAsT

this is really hard - I am curious if same thing appear in cake.frosting - if yes then cloning repo of MS.D.SqlClient will be necessary

AdaskoTheBeAsT avatar Nov 16 '21 19:11 AdaskoTheBeAsT

in frosting there is no problem... image

AdaskoTheBeAsT avatar Nov 18 '21 18:11 AdaskoTheBeAsT

...but :smile: it seems that in cake 1.3.0 it was fixed - can you please force upgrade to 1.3.0?

this is from my machine image

AdaskoTheBeAsT avatar Nov 18 '21 19:11 AdaskoTheBeAsT

Ok! I'll give a try with 1.3 version and I'll let you know.

Em qui., 18 de nov. de 2021 16:05, Adam Pluciński @.***> escreveu:

...but 😄 it seems that in cake 1.3.0 it was fixed - can you please force upgrade to 1.3.0?

this is from my machine [image: image] https://user-images.githubusercontent.com/1914201/142480354-3eafbfb9-a49b-4cb3-a739-3f7cd186b511.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cake-build/cake/issues/3540#issuecomment-973170417, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAL64CIT7JKZ5FF2QB3OE63UMVFA3ANCNFSM5FRR4Z4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

rodrigoramos avatar Nov 19 '21 02:11 rodrigoramos

@AdaskoTheBeAsT @rodrigoramos FYI I still see the same error with Cake 1.3.0:

image

#addin "nuget:?package=Microsoft.Data.SqlClient&version=3.0.0&loaddependencies=true"

var target = Argument("target", "Test");

Task("Test")
  .Does(() =>
{
      const string connStr = "Data Source=server;";

      var conn = new Microsoft.Data.SqlClient.SqlConnection(connStr);
 });

 RunTarget(target);

augustoproiete avatar Nov 19 '21 13:11 augustoproiete

That is really mysterious thing - i will try to uninstall vs mono etc and start with clean state

AdaskoTheBeAsT avatar Nov 19 '21 17:11 AdaskoTheBeAsT

hi

@rodrigoramos @augustoproiete could you please check with .net core 6.0.101?

it seems it is not connected with cake

https://github.com/dotnet/SqlClient/issues/1427

AdaskoTheBeAsT avatar Dec 23 '21 16:12 AdaskoTheBeAsT

Is this still an issue I just in Cake 2.1 tried the following

#addin nuget:?package=Microsoft.Data.SqlClient&version=4.1.0&loaddependencies=true

var target = Argument("target", "Test");

Task("Test")
  .Does(() =>
  {
      const string connStr = "Data Source=localhost,1433;Integrated Security=False;User ID=SA;Password=YourStrong@Passw0rd;Encrypt=False";

      var conn = new Microsoft.Data.SqlClient.SqlConnection(connStr);

      conn.Open();
  });

 RunTarget(target);

And it ran without error image

devlead avatar Apr 03 '22 20:04 devlead

This issue seems to have been fixed, if issue persists please feel free to reopen issue.

devlead avatar Oct 27 '22 19:10 devlead

This issue seems to have been fixed, if issue persists please feel free to reopen issue.

Nope, happens again:

Resolving assembly 'Microsoft.Data.SqlClient.resources, Version=5.0.0.0, Culture=en-US, PublicKeyToken=23ec7fc2d6eaa4a5' using runtime installed at 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.3'... Exception occurred while resolving assembly Microsoft.Data.SqlClient.resources: Could not load file or assembly 'Microsoft.Data.SqlClient.resources, Version=5.0.0.0, Culture=en-US, PublicKeyToken=23ec7fc2d6eaa4a5'. The system cannot find the file specified. Trying to resolve assembly Microsoft.Data.SqlClient.resources as 'Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=en-US, PublicKeyToken=23ec7fc2d6eaa4a5'... Assembly Microsoft.Data.SqlClient resolved as 'Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' (file location: 'C:\Projects......\tools\Addins\Microsoft.Data.SqlClient.5.1.0\runtimes\win\lib\net6.0\Microsoft.Data.SqlClient.dll')

Sebazzz avatar Mar 02 '23 14:03 Sebazzz

@Sebazzz Do you have a Cake script that reproduces this error?

augustoproiete avatar Mar 02 '23 14:03 augustoproiete

#addin nuget:?package=Microsoft.Data.SqlClient&version=5.1.0&loaddependencies=true
using Microsoft.Data.SqlClient;

var connectionString = $"Data Source=localhost;Application Name=Build Script;Initial Catalog=master;Integrated Security=true;Encrypt=false";

void ExecuteSqlCommand(string command) {
	Verbose("Opening connection to {0}", connectionString);
	using SqlConnection sqlConnection = new(connectionString);
	sqlConnection.Open();
	
	Verbose("Executing command: {0}", command);
	using SqlCommand cmd = (SqlCommand) sqlConnection.CreateCommand();
	cmd.CommandText = command;
	cmd.ExecuteNonQuery();
}

ExecuteSqlCommand("SELECT 1");

Running under .NET SDK 7.0.100.

Sebazzz avatar Mar 02 '23 14:03 Sebazzz

@Sebazzz What OS are you running this on?

I'm not able to reproduce (on my laptop at least):

  • macOS Ventura 13.2.1
  • Cake Tool v3.0.0
Analyzing build script...
Processing build script...
Installing addins...
Compiling build script...
Opening connection to Data Source=localhost;Application Name=Build Script;Initial Catalog=master;Integrated Security=true;Encrypt=false

dotnet tool list
Package Id      Version      Commands         Manifest                                                       
-------------------------------------------------------------------------------------------------------------
cake.tool       3.0.0        dotnet-cake      /Users/augustoproiete/cake/tool/3.0.0/.config/dotnet-tools.json

dotnet --info
.NET SDK:
 Version:   7.0.101
 Commit:    bb24aafa11

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.2
 OS Platform: Darwin
 RID:         osx.13-x64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.101/

Host:
  Version:      7.0.1
  Architecture: x64
  Commit:       97203d38ba

.NET SDKs installed:
  3.1.202 [/usr/local/share/dotnet/sdk]
  3.1.300 [/usr/local/share/dotnet/sdk]
  3.1.301 [/usr/local/share/dotnet/sdk]
  3.1.302 [/usr/local/share/dotnet/sdk]
  3.1.402 [/usr/local/share/dotnet/sdk]
  3.1.414 [/usr/local/share/dotnet/sdk]
  5.0.100 [/usr/local/share/dotnet/sdk]
  5.0.102 [/usr/local/share/dotnet/sdk]
  5.0.203 [/usr/local/share/dotnet/sdk]
  5.0.402 [/usr/local/share/dotnet/sdk]
  6.0.100 [/usr/local/share/dotnet/sdk]
  6.0.101 [/usr/local/share/dotnet/sdk]
  6.0.301 [/usr/local/share/dotnet/sdk]
  7.0.100 [/usr/local/share/dotnet/sdk]
  7.0.101 [/usr/local/share/dotnet/sdk]

augustoproiete avatar Mar 02 '23 19:03 augustoproiete

@augustoproiete I can't either anymore. I think Cake doesn't honor loaddependencies if the main dependency is already locally restored - because after a clean build I was able to use it as expected.

Sebazzz avatar Mar 11 '23 21:03 Sebazzz

@Sebazzz I tried building a few times both on OSX and Windows 11 and couldn't reproduce. If you find a way to repro this let us know

augustoproiete avatar Mar 11 '23 22:03 augustoproiete