Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions src/dotnet-ef/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public static Project FromFile(
var exitCode = Exe.Run("dotnet", args, handleOutput: line => output.AppendLine(line));
if (exitCode != 0)
{
if (framework == null && HasMultipleTargetFrameworks(file))
{
throw new CommandException(Resources.MultipleTargetFrameworks);
}

throw new CommandException(Resources.GetMetadataFailed);
}

Expand Down Expand Up @@ -131,6 +136,21 @@ private record class ProjectMetadata
public Dictionary<string, Dictionary<string, string>[]> Items { get; set; } = null!;
}

private static bool HasMultipleTargetFrameworks(string file)
{
var args = new List<string> { "msbuild", "/getProperty:TargetFrameworks", file };

var output = new StringBuilder();
var exitCode = Exe.Run("dotnet", args, handleOutput: line => output.AppendLine(line));
if (exitCode != 0)
{
return false;
}

var outputString = output.ToString();
return !string.IsNullOrEmpty(outputString) && !outputString.IsWhiteSpace();
}

private static void CopyBuildHost(
Dictionary<string, string>[] runtimeCopyLocalItems,
string targetDir)
Expand Down
8 changes: 7 additions & 1 deletion src/dotnet-ef/Properties/Resources.Designer.cs

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

3 changes: 3 additions & 0 deletions src/dotnet-ef/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@
<data name="MultipleStartupProjects" xml:space="preserve">
<value>More than one project was found in the current working directory. Use the --startup-project option.</value>
</data>
<data name="MultipleTargetFrameworks" xml:space="preserve">
<value>The project targets multiple frameworks. Use the --framework option to specify which target framework to use.</value>
</data>
<data name="NamespaceDescription" xml:space="preserve">
<value>The namespace to use. Matches the directory by default.</value>
</data>
Expand Down
6 changes: 5 additions & 1 deletion src/dotnet-ef/RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ protected override int Execute(string[] _)
Reporter.WriteVerbose(Resources.UsingProject(projectFile));
Reporter.WriteVerbose(Resources.UsingStartupProject(startupProjectFile));

var project = Project.FromFile(projectFile);
var project = Project.FromFile(
projectFile,
_framework!.Value(),
_configuration!.Value(),
_runtime!.Value());
var startupProject = Project.FromFile(
startupProjectFile,
_framework!.Value(),
Expand Down
Loading