Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Core support #39

Open
jnm2 opened this issue Nov 3, 2017 · 36 comments
Open

.NET Core support #39

jnm2 opened this issue Nov 3, 2017 · 36 comments
Milestone

Comments

@jnm2
Copy link
Contributor

jnm2 commented Nov 3, 2017

Scripts that use Cake.SqlServer cannot be run or debugged using CoreCLR.

Can we add a netstandard1.6 build to the package? It's okay if things like DACPAK are missing initially; I don't use them.

Willing to help/PR.

@trailmax
Copy link
Contributor

trailmax commented Nov 3, 2017

There was an attempt to migrate initially, but got abandoned: #19

Feel free to PR if you need it sooner. I tried to get it migrated, but BACPAC/DACPAC dependencies are not yet on Core and I did not want a partial solution. But let's go there without it, as it is causing too much pain already.

@trailmax
Copy link
Contributor

trailmax commented Nov 3, 2017

I've done Cake.Hosts to work on both full-fat framework and Core - can use it as example for build script as that will have to be updated

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 3, 2017

Mind if I move you to the modern csproj SDK too, like Cake.Hosts?

@trailmax
Copy link
Contributor

trailmax commented Nov 3, 2017

@jnm2 go wild!

@trailmax
Copy link
Contributor

trailmax commented Nov 3, 2017

@jnm2 I mean without breaking compatibility ;-P

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 3, 2017

Awww...

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 3, 2017

Do you care if I get rid of the Copy-Files task which stages bin files to an intermediate directory and use MSBuild .WithTarget("Pack") to handle pulling all the files for the nupkg?

This is what I have so far: master...jnm2:dotnet_core_support

The last remaining part of the upgrade is to create a multi-targeting nupkg which can either be done manually (which is brittle to changing target frameworks or changing dependencies) or with MSBuild magic.

@trailmax
Copy link
Contributor

trailmax commented Nov 3, 2017

@jnm2 Looks a lot cleaner - at least the projects files
Copy-Files task is a hack, so if it can be fixed go ahead.

The remaining the the hard part - building for multi-platforms is hard.

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 3, 2017

Cool.
One commit at a time. =) Makes it easier to dissect later if needed.

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 4, 2017

Right now you have <authors>Max Vasilyev</authors><owners>trailmax, cake-contrib</owners>. Do you want to keep that or are you equally happy with <authors>Max Vasilyev</authors><owners>Max Vasilyev</owners> like Cake.Hosts has?

(The difference is whether to use an external .nuspec or do it all from the .csproj.)

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 4, 2017

You should add an appveyor.yml to the repo to make it easy for me to set up my own AppVeyor test on my own fork.

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 4, 2017

@trailmax
Copy link
Contributor

trailmax commented Nov 4, 2017

@jnm2 re <authors> - keep it simple, if we can have a working solution without extra nuspec file - let's do it.
As for the problem of loading assemblies - I have no clue

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 4, 2017

Cool, thanks. I think you should erase the API keys in that comment though or a bot will pick them up for sure. I don't think I need them.

@trailmax
Copy link
Contributor

trailmax commented Nov 4, 2017

These are encrypted by appveyor, so no worries.

@Kemyke
Copy link

Kemyke commented Nov 22, 2017

Guys, may i ask how this issue is going? We are really waiting to use this library in our build process. Can we expect a pull request or new version soon? Or can we help you somehow to port the library?

@trailmax
Copy link
Contributor

@Kemyke as @jnm2 says above - he is blocked by Cake's inability to pull Core dependencies - see the link to exception a few messages above. I've not had a chance to do any of this, so @jnm2 is doing all the work here.

@Kemyke
Copy link

Kemyke commented Nov 22, 2017

Hey @jnm2 which bootstrapper did you use? Currently i am using cake in a dotnet core environment on Ubutnu so there are dotnet core compatible addins out there. I got the same error as you when i use the full framework cake bootstrapper. Did you use the core compatible bootstrapper? Unfortunatelly on the official site it is not available but you can find one here: https://github.com/devlead/BitbucketPipelinesShield/blob/master/build.ps1

The main point to install the Cake.CoreCLR dll and not the Cake.exe.

Hope this help solving your issue.

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 22, 2017

@Kemyke Interesting. Unfortunately, publishing an addin that breaks everyone unless they switch their bootstrapper to run their scripts on .NET Core is not something I see as a good thing. What if I'm using an unrelated addin that requires .NET Framework (like this one currently does)?

@Kemyke
Copy link

Kemyke commented Nov 22, 2017

No it won't be breaking change. You should create a nuget package which contains the full framework and the core packages. You can control the target frameworks in the csproj. (eg: net46;netstandard16)

@Kemyke
Copy link

Kemyke commented Nov 22, 2017

Check this addin for example: Cake.FileHelpers You can download the nupkg (https://www.nuget.org/packages/Cake.FileHelpers/) and check the nuspec file, you can find the multiple targetFramework in it.

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 22, 2017

@Kemyke That's exactly what we're doing; unfortunately, the approach you suggest is currently blocked. See https://gitter.im/cake-build/cake?at=59fe39f74ff065ac18b78e65.

@trailmax
Copy link
Contributor

@jnm2 probably worth copying the exception you get into this thread

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 22, 2017

Relevant log output:

The addin Cake.SqlServer will reference Cake.SqlServer.dll.
The addin Cake.SqlServer will reference System.Data.Common.dll.
The addin Cake.SqlServer will reference System.Data.SqlClient.dll.
Loaded 'c:/Users/Joseph/Desktop/test/tools/Addins/cake.sqlserver/Cake.SqlServer/lib/netstandard1.6/Cake.SqlServer.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Verifying assembly 'Cake.SqlServer, Version=1.8.5.0, Culture=neutral, PublicKeyToken=null'.
Loaded 'c:/Users/Joseph/Desktop/test/tools/Addins/cake.sqlserver/Cake.SqlServer/lib/netstandard1.6/System.Data.Common.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Verifying assembly 'System.Data.Common, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Loaded 'c:/Users/Joseph/Desktop/test/tools/Addins/cake.sqlserver/Cake.SqlServer/lib/netstandard1.6/System.Data.SqlClient.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Verifying assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load c:/Users/Joseph/Desktop/test/tools/Addins/cake.sqlserver/Cake.SqlServer/lib/netstandard1.6/Cake.SqlServer.dll (missing System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a))
Could not load file or assembly 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Could not load file or assembly 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Could not load file or assembly 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Could not load file or assembly 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Could not load file or assembly 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Could not load file or assembly 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Could not load file or assembly 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Could not load file or assembly 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Could not load file or assembly 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Could not load c:/Users/Joseph/Desktop/test/tools/Addins/cake.sqlserver/Cake.SqlServer/lib/netstandard1.6/System.Data.SqlClient.dll (missing System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)

Adding assembly reference to Cake.SqlServer.dll...
Adding assembly reference to System.Data.Common.dll...
Adding assembly reference to System.Data.SqlClient.dll...
Error: Cake.Core.CakeException: Error occurred when compiling build script: c:/Users/Joseph/Desktop/test/build.cake(3,1): error CS0103: The name 'OpenSqlConnection' does not exist in the current context
(2483,5): warning CS1702: Assuming assembly reference 'System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' used by 'System.Data.SqlClient' matches identity 'System.Data.Common, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' of 'System.Data.Common', you may need to supply runtime policy
   at Cake.Scripting.Roslyn.RoslynScriptSession.Execute(Script script)
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments)
   at Cake.Commands.DebugCommand.Execute(CakeOptions options)
   at Cake.CakeApplication.Run(CakeOptions options)
   at Cake.Program.Main()
The program '[12692] Cake.dll' has exited with code 1 (0x1).

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 22, 2017

The net46 target works fine, but there's no point in going ahead and adding the netstandard1.6 target until it works on Cake with the default bootstrapper and default configuration.
What makes this addin unique from FileHelpers and others I've looked at is that this one has a package dependency beyond just NETStandard.Library.

@Kemyke
Copy link

Kemyke commented Nov 22, 2017

Ok, i can reproduce your error from your branch. Taking a look at it...

@jnm2
Copy link
Contributor Author

jnm2 commented Nov 22, 2017

@Kemyke If you see a way through that I didn't, or you feel like 'being the change we want to see' 😬 in Cake, please take the lead. I've been so busy!

@Kemyke
Copy link

Kemyke commented Nov 23, 2017

This must be a Cake bug, i have to investigate it further.
What i have done for now:

  • Created a nuget from your branch

  • Uploaded it to our own nuget server

  • If i referenced it from a dotnet core project it was working as expected. (e.g. i could drop my test db)

  • If i referenced from a cake script. First i got the same exception as you. So Cake couldn't find the referenced assemblies.

  • Then i published the project which copies all the references in one place and created a nuget package from that.

  • In this case the Cake could find the assembly but i also got error, like the Cake was loading a wrong assembly:

Could not load C:/mypath/Cake.SqlServer.0.0.2/lib/netstandard1.6/Cake.SqlServer.dll (missing System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a))
Could not load C:/mypath/Cake.SqlServer.0.0.2/lib/netstandard1.6/System.Data.SqlClient.dll (missing System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
Could not load C:/mypath/Cake.SqlServer.0.0.2/lib/netstandard1.6/runtimes/unix/lib/netstandard1.3/System.Data.SqlClient.dll (missing System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
Could not load C:/mypath/Cake.SqlServer.0.0.2/lib/netstandard1.6/runtimes/win/lib/netstandard1.3/System.Data.SqlClient.dll (missing System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)

========================================
DropDb
========================================
An error occurred when executing task 'DropDb'.

Unhandled Exception: System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform.
   at System.Data.SqlClient.SqlConnection.Dispose(Boolean disposing)
   at System.Data.Common.DbConnection.Finalize()
Error: One or more errors occurred. (System.Data.SqlClient is not supported on this platform.)
        System.Data.SqlClient is not supported on this platform.

Now i am trying to dig deeper.

@trailmax
Copy link
Contributor

trailmax commented Mar 1, 2018

Since Cake now supports .Net Core, can you guys try this again please?

@IvorBright
Copy link

Another request for .Net Core support please.

@jnm2
Copy link
Contributor Author

jnm2 commented Jan 27, 2019

Sadly, I don't have time to invest in this anymore. I'm moving in a different direction for build scripts.

@trailmax
Copy link
Contributor

@jnm2 What are you doing, if you don't mind me asking here?

@IvorBright I think I have a plan for getting .Net Core to this project. Hopefully will get this done in a next few weeks.

@jnm2
Copy link
Contributor Author

jnm2 commented Jan 29, 2019

@trailmax I've been looking for options that don't add much overhead time and that scale easily when the complexity increases to many files. For simple Windows projects, I tried PowerShell because it's hands down the fastest (it's its own bootstrapper) and is easy to use for simple scripts by invoking dotnet or vswhere. I'll definitely be doing more of that for small scripts.

For more complex projects, making the build script a console app and bootstrapping with dotnet run gives fast cold startup, caches the compilation for even faster warm startup, and brings the full power of the IDE. It's not painful anymore to move classes to new files, rename things, generate constructors... all of the things that should be frictionless when you're managing complexity. One example of this kind of complexity is generating WiX XML fragments programmatically.

I'm getting a boost by using https://nuke.build/ for now to avoid writing everything from scratch, but I could see myself wanting to be fully custom too. Still figuring it out. I sorta like the mentality of plugging in pre-built parts to save time, such as parsing CLI arguments and tracking targets, while feeling free to customize other parts to fit the project, such as parallelism or console output. (I'm keeping my eye on https://github.com/dotnet/command-line-api/wiki/DragonFruit-overview.)

@trailmax
Copy link
Contributor

@jnm2 Ah, that sounds like the exactly same issues I've been hitting with Cake as well. On one of my builds I noticed that Cake warm-up time was 5 minutes(!!!) and the actual build another 4min. And yes, creating build scripts are a pain with Cake.

Nuke.build looks intersting - I'll check it out.

@jnm2
Copy link
Contributor Author

jnm2 commented Jan 29, 2019

@trailmax Hope that was helpful! I'm certainly not interested in discouraging you from using Cake.

@AdaskoTheBeAsT
Copy link
Member

hi, .NET core support was introduced in #66
Please check if you encounter any issues in that - if not then that thread can be closed

@augustoproiete augustoproiete added this to the v3.0.0 milestone May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants