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

Cannot switch Migrations environment target from Visual Studio #13975

Closed
tudordid opened this issue Nov 16, 2018 · 3 comments
Closed

Cannot switch Migrations environment target from Visual Studio #13975

tudordid opened this issue Nov 16, 2018 · 3 comments

Comments

@tudordid
Copy link

tudordid commented Nov 16, 2018

This might be a regression of the issue originally reported in #9623, but I am unable to change my migration target from the PS session in Visual Studio (using the Package Manager Console PS session) for an ASP.NET Core project backed up by EF Core 2.1.

I tried setting the environment variable to the target environment I want, confirmed the variable is set, but as shown below, the migration still runs in the context of the default Development environment.

PM> $env:ASPNETCORE_ENVIRONMENT="Test"
PM> Get-ChildItem env:ASPNETCORE_ENVIRONMENT

Name                           Value                                                                                                                                                                                                                                                                                            
----                           -----                                                                                                                                                                                                                                                                                            
ASPNETCORE_ENVIRONMENT         Test                                                                                                                                                                                                                                                                                             


PM> Update-Database -Verbose
Using project 'DataApp'.
Using startup project 'DataApp'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile D:\code\data\src\Product\DataApp\bin\Debug\netcoreapp2.1\DataApp.deps.json --additionalprobingpath C:\Users\tudordid\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig D:\code\data\src\Product\DataApp\bin\Debug\netcoreapp2.1\DataApp.runtimeconfig.json C:\Users\tudordid\.nuget\packages\microsoft.entityframeworkcore.tools\2.1.4\tools\netcoreapp2.0\any\ef.dll database update --verbose --no-color --prefix-output --assembly D:\code\data\src\Product\DataApp\bin\Debug\netcoreapp2.1\DataApp.dll --startup-assembly D:\code\data\src\Product\DataApp\bin\Debug\netcoreapp2.1\DataApp.dll --project-dir D:\code\data\src\Product\DataApp\ --language C# --working-dir D:\code\data --root-namespace DataApp
Using assembly 'DataApp'.
Using startup assembly 'DataApp'.
Using application base 'D:\code\data\src\Product\DataApp\bin\Debug\netcoreapp2.1'.
Using working directory 'D:\code\data\src\Product\DataApp'.
Using root namespace 'DataApp'.
Using project directory 'D:\code\data\src\Product\DataApp\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding IWebHost accessor...
Using environment 'Development'.
Using application service provider from IWebHost accessor on 'Program'.

Checking up on my environment variable right after this failure shows that it is no longer assigned:

PM> Get-ChildItem env:ASPNETCORE_ENVIRONMENT
Get-ChildItem : Cannot find path 'ASPNETCORE_ENVIRONMENT' because it does not exist.
At line:1 char:1
+ Get-ChildItem env:ASPNETCORE_ENVIRONMENT
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (ASPNETCORE_ENVIRONMENT:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

The original posted for issue #9623 eventually reported this working for him, but since that was more than a year ago, I wonder if this a regression in the tool.

I am able to make this work if I set the environment variable in a CMD / PS session before I run Visual Studio, and then start VS from the same session, basically having the variable already available in the package manager. However, trying to override it there to switch to a different environment renders the same behavior, in the sense that my override is ignored and it only runs against the initial environment I set before running VS.

Further technical details

EF Core version: 2.1.4
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017 15.9.1
PS Version: 5.1.17763.134

@bricelam
Copy link
Contributor

bricelam commented Jun 20, 2019

I'm not able to repro this. For me, environment variables are persisted in PMC and copied into child processes. You may want to follow up on NuGet/Home.

PM> $env:FOO = 1
PM> $env:FOO
1
PM> cmd /C "SET FOO"
FOO=1

@bricelam bricelam removed this from the 3.0.0 milestone Jun 20, 2019
@divega
Copy link
Contributor

divega commented Jun 20, 2019

@tudordid would you be able to provide more details to help us repro?

@ajcvickers
Copy link
Contributor

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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

4 participants