Skip to content

Powershell commands do not work on csproj #5036

Closed as not planned
Closed as not planned

Description

@natemcmaster

The Package Manager Console powershell commands does not currently work on projects using csproj.

Issues:

  • OperationHandlers.cs does not compile. (Fix already in Fix powershell commands #5037 )
  • Cannot new-up a DbContext at design time due to "MissingMethodException" in MemoryCacheServiceCollectionExtensions

Repro

File -> New Project... (Console App)
Add this a simple dbcontext.

    public class TestContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Database=test;Server=(localdb)\\mssqllocaldb");
        }
    }

From PMC

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Pre -Source https://www.myget.org/F/aspnetcirelease/
Install-Package Microsoft.EntityFrameworkCore.Commands -Pre -Source https://www.myget.org/F/aspnetcirelease/
Add-Migration FirstMigration

First error looks like

The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: c:\Users\namc\Documents\Visual Studio 2015\Projects\ClassLibrary2\packages\Microsoft.EntityFrameworkCore.Commands.1.0.0-rc2-20529\tools\OperationHandlers.cs(35) : ; expected

c:\Users\namc\Documents\Visual Studio 2015\Projects\ClassLibrary2\packages\Microsoft.EntityFrameworkCore.Commands.1.0.0-rc2-20529\tools\OperationHandlers.cs(34) : 

c:\Users\namc\Documents\Visual Studio 2015\Projects\ClassLibrary2\packages\Microsoft.EntityFrameworkCore.Commands.1.0.0-rc2-20529\tools\OperationHandlers.cs(35) : >>>         public virtual int Version => 0;

c:\Users\namc\Documents\Visual Studio 2015\Projects\ClassLibrary2\packages\Microsoft.EntityFrameworkCore.Commands.1.0.0-rc2-20529\tools\OperationHandlers.cs(36) : 

When OperationHandler.cs is fixed, the error is:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
---> System.MissingMethodException: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Extensions.DependencyInjection.MemoryCacheServiceCollectionExtensions.AddMemoryCache(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
   at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServiceCollectionExtensions.AddQuery(IServiceCollection serviceCollection)
   at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServiceCollectionExtensions.AddEntityFramework(IServiceCollection serviceCollection)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>b__1(Int64 k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options)
   at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
   at Microsoft.EntityFrameworkCore.DbContext..ctor()
   at ClassLibrary2.TestContext..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.EntityFrameworkCore.Design.DbContextOperations.<>c__DisplayClass11_3.<FindContextTypes>b__13()
   at Microsoft.EntityFrameworkCore.Design.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

Activity

  1. changed the title [-][rc2] Powershell do not work on csproj[/-] [+][rc2] Powershell commands do not work on csproj[/+] on Apr 11, 2016
  2. natemcmaster commented on Apr 11, 2016

    @natemcmaster
    ContributorAuthor

    cc @divega I started a little investigation, but couldn't find a reason for this bug.

  3. BradBarnich commented on Apr 12, 2016

    @BradBarnich

    Additionally, on VS15 I get this:

    System.Management.Automation.MethodInvocationException: 
      Exception calling "CreateDomain" with "3" argument(s): "The domain manager specified by the host could not be instantiated." ---> 
      System.TypeLoadException: The domain manager specified by the host could not be instantiated. ---> 
      System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Platform.AppDomainManager, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
       at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
       at System.Activator.CreateInstance(String assemblyName, String typeName)
       at System.AppDomain.CreateInstance(String assemblyName, String typeName)
       at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
       at System.AppDomain.CreateAppDomainManager()
       --- End of inner exception stack trace ---
       at System.AppDomain.CreateAppDomainManager()
       at System.AppDomain.Setup(Object arg)
       at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
       at System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
       at System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
       at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
       at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
    

    With VS2015, on a csproj, build 1.0.0-rc3-20540, Add-Migration does work with the changes to OperationHandlers.cs

  4. natemcmaster commented on Apr 12, 2016

    @natemcmaster
    ContributorAuthor
  5. BradBarnich commented on Apr 12, 2016

    @BradBarnich

    @natemcmaster used 1.0.0-rc2-20539, same result. With the fixes to OperationHandlers.cs, VS2015 works and VS15 does not.

  6. natemcmaster commented on Apr 12, 2016

    @natemcmaster
    ContributorAuthor

    @BradBarnich the issue you are seeing in VS15 Preview is the likely the same issue added here: NuGet/Home#2162. As you'll see, the issue was closed because it is a bug in VS itself.

  7. natemcmaster commented on Apr 12, 2016

    @natemcmaster
    ContributorAuthor

    Update: with fixes to OperationHandler.cs, the error does not reproduce on all machines. I tried on a clean install of VS2015.

  8. changed the title [-][rc2] Powershell commands do not work on csproj[/-] [+]Powershell commands do not work on csproj[/+] on Apr 12, 2016
  9. natemcmaster commented on Apr 12, 2016

    @natemcmaster
    ContributorAuthor

    Closed via #5037

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions