Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Microsoft.EntityFrameworkCore.Tools/DispatchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel;
Expand Down Expand Up @@ -97,7 +98,7 @@ public static CommandLineApplication Create()
}

// TODO remove when https://github.com/dotnet/cli/issues/2645 is resolved
Func<bool> isClassLibrary = () =>
Func<bool> isClassLibrary = () =>
{
var projectContext = ProjectContext.Create(
projectFile.ProjectFilePath,
Expand Down Expand Up @@ -149,6 +150,10 @@ public static CommandLineApplication Create()
{
Reporter.Error.WriteLine(ToolsStrings.ClassLibrariesNotSupportedInCli(fwlink));
}
else if (framework.IsDesktop() && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Reporter.Error.WriteLine(ToolsStrings.DesktopCommandsRequiresWindows(framework.GetShortFolderName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does we require Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET Core CLI doesn't launch exes on non-Windows. This would require mono.

}
else
{
// intentionally put DispatcherToolName in error because "Microsoft.EntityFrameworkCore.Tools.Cli" is
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="ClassLibrariesNotSupportedInCli" xml:space="preserve">
<value>This preview of Entity Framework tools does not support targeting class library projects in ASP.NET Core and .NET Core applications. See {fwlink} for details and workarounds.</value>
</data>
<data name="DesktopCommandsRequiresWindows" xml:space="preserve">
<value>Could not invoke this command on this project. Commands for framework '{framework}' are only supported on Windows.</value>
</data>
<data name="LogBeginDispatch" xml:space="preserve">
<value>Invoking dependency command '{projectCommand}' in project '{projectName}'</value>
</data>
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.EntityFrameworkCore.Tools/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"Microsoft.NETCore.App": {
"version": "1.0.0-*",
"type": "platform"
}
},
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-*"
}
},
"net451": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
@{
# Script module or binary module file associated with this manifest
ModuleToProcess = 'EntityFrameworkCore.PowerShell2.psm1'

# Version number of this module.
ModuleVersion = '1.0.0'

# ID used to uniquely identify this module
GUID = '2de7c7fd-c848-41d7-8634-37fed4d3bb36'

# Author of this module
Author = 'Entity Framework Team'

# Company or vendor of this module
CompanyName = 'Microsoft Corporation'

# Copyright statement for this module
Copyright = '(c) .NET Foundation. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Entity Framework PowerShell module used for the Package Manager Console'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '1.0'

# Name of the Windows PowerShell host required by this module
PowerShellHostName = 'Package Manager Host'

# Minimum version of the Windows PowerShell host required by this module
PowerShellHostVersion = '1.2'

# Minimum version of the .NET Framework required by this module
DotNetFrameworkVersion = '4.0'

# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = ''

# Processor architecture (None, X86, Amd64, IA64) required by this module
ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = 'NuGet'

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module
ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = @()

# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = @()

# Functions to export from this module
FunctionsToExport = (
'Add-Migration',
'Enable-Migrations',
'Remove-Migration',
'Scaffold-DbContext',
'Script-Migration',
'Update-Database',
'Use-DbContext'
)

# Cmdlets to export from this module
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = @()

# Aliases to export from this module
AliasesToExport = @()

# List of all modules packaged with this module
ModuleList = @()

# List of all files packaged with this module
FileList = @()

# Private data to pass to the module specified in ModuleToProcess
PrivateData = ''
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$ErrorActionPreference = 'Stop'

$versionErrorMessage = "EF commands do not support PowerShell version $($PSVersionTable.PSVersion). Please upgrade PowerShell to 3.0 or greater and restart Visual Studio."

function Add-Migration {
throw $versionErrorMessage
}

function Enable-Migrations {
throw $versionErrorMessage
}

function Remove-Migration {
throw $versionErrorMessage
}

function Scaffold-DbContext {
throw $versionErrorMessage
}

function Script-Migration {
throw $versionErrorMessage
}

function Update-Database {
throw $versionErrorMessage
}

function Use-DbContext {
throw $versionErrorMessage
}
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ function InvokeDotNetEf($project, [switch] $json, [switch] $skipBuild) {
}
if (!$t) {
$projectName = $project.ProjectName
throw "Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project '$projectName'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json."
throw "Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project '$projectName'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details."
}

$output = $null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ SHORT DESCRIPTION
Provides information about Entity Framework Core commands.

LONG DESCRIPTION
This topic describes the Entity Framework Core commands. Entity Framework is Microsoft's recommended data access technology
for new applications.
This topic describes the Entity Framework Core commands. See https://docs.efproject.net for information on Entity Framework Core.

The following Entity Framework cmdlets are included.

Expand Down
19 changes: 16 additions & 3 deletions src/Microsoft.EntityFrameworkCore.Tools/tools/init.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
param ($installPath, $toolsPath, $package, $project)

if (Get-Module | ? Name -eq EntityFrameworkCore) {
Remove-Module EntityFrameworkCore
if ($PSVersionTable.PSVersion.Major -lt 3) {
# This section needs to support PS 2.0 syntax
# Use $toolsPath because PS 2 does not support $PSScriptRoot
$env:PSModulePath= $env:PSModulePath + ";$toolsPath"

# import a "dummy" module that contains matching functions that throw on PS2
Import-Module ([System.IO.Path]::Combine($toolsPath, "EntityFrameworkCore.PowerShell2.psd1")) -DisableNameChecking

throw "EF commands do not support PowerShell version $($PSVersionTable.PSVersion). Please upgrade PowerShell to 3.0 or greater and restart Visual Studio."
} else {

if (Get-Module | ? Name -eq EntityFrameworkCore) {
Remove-Module EntityFrameworkCore
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shame PowerShell doesn't just do this using the package metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PowerShell will actually throw an error on PS 2.0 because of syntax errors...but yeah, PS2 ignores metadata in psd1

Import-Module (Join-Path $PSScriptRoot EntityFrameworkCore.psd1) -DisableNameChecking
}

Import-Module (Join-Path $PSScriptRoot EntityFrameworkCore.psd1) -DisableNameChecking