Can't enable migrations in VS.2017 with ASP.NET Core web app

I started building my ASP.NET web application using the ASP.NET Core template. I noticed that it already has two files in the ~ \ Data \ Migrations folder: naemd * _CreateIdentitySchema.cs and another ApplicationDbContextModelSnapshot.

At first I complained that I had Powershell 2, so I installed v3. Then I installed the EntityFramework package (v6.1.3) from the package manager because somehow this was not installed from the template as it was in VS.2015.

Now it gives me an error like " Exception calling" SetData "with arguments" 2 ": " and then a bunch of things.

 $domain.SetData('contextProject', $contextProject)
 CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
  FullyQualifiedErrorId : SerializationException
 Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, 

      

Version = 15.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a 'not marked serializable. "In C: \ Users \ Devel.nuget \ packages \ entityframework \ 6.1.3 \ tools \ EntityFramework.psm1: 720 char: 5 + $ domain.SetData ('startUpProject', $ startUpProject)

I am using VS.2017 Update 1, I get the impression that this "basic" thing makes life harder, not simplifies it.

+3


source to share


2 answers


I am doing the following:

  • Set the unit test project as the StartUp project,
  • Install the platform for any processor,
  • Added an empty constructor to the context (without calling the base ("name = XXX")).

Then I issued this command Enable-Migrations



Enable-Migrations -ProjectName "MyProjectWithContext" -ConnectionString "Data Source =. \ SQL; Initial Directory = XXXXX; Integrated Security = True; MultipleActiveResultSets = True" -ConnectionProviderName System.Data.SqlClient

Same for Add-Migration

Add-Migration -Name MyName -ProjectName "MyProject" -ConnectionString "Data Source =. \ SQL; Initial Directory = XXXX; Integrated Security = True; MultipleActiveResultSets = True" -ConnectionProviderName System.Data.SqlClient

+2


source


Not sure if this helps: I had the same problem after placing my projects in a project targeting .NET 4.6.2, but using the "new" MSBuild syntax (I think it's called).

Projectname.csproj (the one containing the code from the entity framework) looks like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>

      

I have now recreated the project using the VS 2017 template "Windows Classic Desktop - Class Library (.NET Framework)" (basically: copy all the code and configure all dependencies again).

Now, Projectname.csproj looks like this (deprecated MSBuild? Not sure how to call it):



<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

      

I can still add a "new" project as a project reference that contains ASP.NET Core stuff. And more importantly, using "Add-Migration" in a project containing EF types now works (EDIT: I still need to follow Damian Surigel's recommendation: the startup project should be another project with a valid app.config).

, , , / MSBuild. , . .

: .NET 4.6 "" . .

+1









All Articles