Tuesday, July 5, 2016

Visual Studio 2015 Update 3 with DotNetCore 1.0.0 SDK install with Entity Framework 7 ( EF7 )

Had some fun today trying to get EF7 to work with dotnet core, but finally got through all the issues I was running into. Let me take you on that journey:

In order to proceed you've got to install the following three items (perhaps just the first two...):
1. Visual Studio 2015 Update 3
2. .NET Core for Visual Studio
3. or choose the installer from https://www.microsoft.com/net/download which I perhaps shouldn't have done.

Links for the above can be found in this article which I also use in my explanations below:
https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html

I installed 1 above, then 2, but was still getting an error. In particular I couldn't get this line to run from this tutorial.
 Install-Package Microsoft.EntityFrameworkCore.Tools –Pre  


To troubleshoot I installed the x86 versions of .NET Core SDK Installer (Preview 2) and .NET Core Installer (v1.0) as well to see if that would help. It did until I rebooted after which no references were being displayed. I quickly reinstalled the .Net Core SDK Installer (Preview 2) x64 versions again and that seemed to do the trick.

All three of the install package commands were now installed without restore failures!:
 Install-Package Microsoft.EntityFrameworkCore.SqlServer  
 Install-Package Microsoft.EntityFrameworkCore.Tools –Pre  
 Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design  


Next I tried to get EF7 to work with a raw .Net Core project following the efproject.net link's instructions which needed a little changing.

First change the project.json to the following:
 {  
  "version": "1.0.0-*",  
  "buildOptions": {  
   "emitEntryPoint": true  
  },  
  "dependencies": {  
   "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",  
   "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",  
   "Microsoft.EntityFrameworkCore.Tools": {  
    "type": "build",  
    "version": "1.0.0-preview2-final"  
   },  
   "Microsoft.NETCore.App": {  
    "type": "platform",  
    "version": "1.0.0"  
   },  
   "Microsoft.EntityFrameworkCore.Design": {  
    "type": "build",  
    "version": "1.0.0-preview2-final"  
   }  
  },  
  "tools": {  
   "Microsoft.EntityFrameworkCore.Tools": {  
    "version": "1.0.0-preview2-final"  
   },  
   "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",  
   "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"  
  },  
  "frameworks": {  
   "netcoreapp1.0": {}  
  }  
 }   


Key point 1: Can't use EF7 against a class library so we added the buildOptions and emitEntryPoint portion per this article. EF7 won't work against a project that is not an application of some sort (i.e. it can't be a class library). Otherwise you'll see these kinds of errors when you try and run Scaffold-DbContext:
 PM> Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer  
 Could not invoke this command on the startup project 'Core.Datav2'. This preview of Entity Framework tools does not support commands on class library projects in ASP.NET Core and .NET Core applications. See http://go.microsoft.com/fwlink/?LinkId=798221 for details and workarounds.  

or if you forgot to add the [STAThread]...static void main(string[] args) in you're Program.cs:
 PM> Scaffold-DbContext "Server=localhost;Database=VbscriptIndexer;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer  
 C:\Program Files\dotnet\dotnet.exe compile-csc @C:\Projects\dotNetCore\Core.Datav2\bin\Core.Datav2\obj\Debug\netcoreapp1.0\dotnet-compile.rsp returned Exit Code 1 C:\Projects\dotNetCore\Core.Datav2\error CS5001: Program does not contain a static 'Main' method suitable for an entry point   
  Build failed on 'Core.Datav2'.   
And if you're still having issues, re-install the .NET Core SDK Install (Preview 2) and try again. I ended up doing it a few times which was a bit annoying but was really self-caused misery.

Saturday, July 2, 2016

Visual Studio VS.Net 2015 RC2 and Typescript

So my Visual Studio solution is throwing a ton of errors due to the latest rx.js component. The Angular2 solution works just fine, VS.Net 2015 RC2 doesn't think so. To resolve the VS 2015 RC2 issue, you can see the fix described at:
https://github.com/Microsoft/TypeScript/issues/8518

This link essentially upgrades your VS.Net 2015 RC2 instances from ts.version 1.8.9 to ts.version 1.8.10 which will fix all the pesky ambient declaration and other similar errors showing up in Visual Studio. 1.8.10 now handles external modules with their nested ambient modules by moving them to imported files since they need to be resolved. As an aside, I found that typings.json resolves much the same issue but in another way.

If you have VS.2015 rc2 you should seriously consider upgrading it with update 3: https://blogs.msdn.microsoft.com/visualstudio/2016/06/27/visual-studio-2015-update-3-and-net-core-1-0-available-now/

Update 3 will take you to ts.version 1.8.34 and should NOT install the ts version 1.8.10 over the top.

Anyways, after installing v 1.8.10 my VS.Net rc2 Angular2 app builds successfully. Will install update 3 tomorrow as it is a 7gb download and can take quite a while to install.