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
4 changes: 2 additions & 2 deletions src/dotnet-ef/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static Project FromFile(
{
Debug.Assert(!string.IsNullOrEmpty(file), "file is null or empty.");

var args = new List<string> { "msbuild", };
var args = new List<string> { "build", "--no-restore", };

Comment thread
jjonescz marked this conversation as resolved.
if (framework != null)
{
Expand Down Expand Up @@ -148,7 +148,7 @@ private record class ProjectMetadata

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

var output = new StringBuilder();
var exitCode = Exe.Run("dotnet", args, handleOutput: line => output.AppendLine(line));
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-ef/Properties/Resources.Designer.cs

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

4 changes: 2 additions & 2 deletions src/dotnet-ef/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
<value>Prefix output with level.</value>
</data>
<data name="ProjectDescription" xml:space="preserve">
<value>The project to use. Defaults to the current working directory.</value>
<value>The project or file-based app to use. Defaults to the current working directory.</value>
</data>
<data name="ProjectExtensionsDescription" xml:space="preserve">
<value>Obsolete</value>
Expand All @@ -376,7 +376,7 @@
<value>Also bundle the .NET runtime so it doesn't need to be installed on the machine.</value>
</data>
<data name="StartupProjectDescription" xml:space="preserve">
<value>The startup project to use. Defaults to the current working directory.</value>
<value>The startup project or file-based app to use. Defaults to the current working directory.</value>
</data>
<data name="SuffixDescription" xml:space="preserve">
<value>The suffix to attach to the name of all the generated files</value>
Expand Down
18 changes: 1 addition & 17 deletions test/dotnet-ef.Tests/DotNetEfConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,25 +264,9 @@ private static string CreateConfig(string directory, string contents)
return configFile;
}

private sealed class TestDirectory : IDisposable
private sealed class TestDirectory : TempDirectory
{
public TestDirectory()
{
Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName());
Directory.CreateDirectory(Path);
}

public string Path { get; }

public string CreateConfig(string contents)
=> DotNetEfConfigTest.CreateConfig(Path, contents);

public void Dispose()
{
if (Directory.Exists(Path))
{
Directory.Delete(Path, recursive: true);
}
}
}
}
95 changes: 95 additions & 0 deletions test/dotnet-ef.Tests/ProjectTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore.Tools;

public sealed class ProjectTest(ITestOutputHelper output)
{
private const string TargetFramework = "net10.0";

[Fact]
public void Csproj_metadata_can_be_extracted()
{
using var directory = new TempDirectory();
var csprojFile = Path.Combine(directory.Path, "MyApp.csproj");
File.WriteAllText(csprojFile, $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>{TargetFramework}</TargetFramework>
</PropertyGroup>
</Project>
""");

Exe.Run("dotnet", ["restore", csprojFile], handleOutput: _ => { });

var project = Project.FromFile(csprojFile);

Assert.Equal("C#", project.Language);
Assert.Equal("MyApp", project.AssemblyName);
Assert.Equal(TargetFramework, project.TargetFramework);
Assert.NotNull(project.OutputPath);
Assert.NotNull(project.ProjectDir);
Assert.Equal("MyApp.dll", project.TargetFileName);
}

[Fact]
public void File_based_app_can_be_built()
{
WithVerboseOutput(() =>
{
using var directory = new TempDirectory();
var csFile = Path.Combine(directory.Path, "MyApp.cs");
File.WriteAllText(csFile, $"""
#:property TargetFramework={TargetFramework}
Console.WriteLine("Hello");
""");

Exe.Run("dotnet", ["restore", csFile], handleOutput: Reporter.WriteVerbose);
Comment thread
jjonescz marked this conversation as resolved.

var project = Project.FromFile(csFile);

Assert.Equal("C#", project.Language);
Assert.Equal("MyApp", project.AssemblyName);
Assert.Equal(TargetFramework, project.TargetFramework);
Assert.NotNull(project.OutputPath);
Assert.NotNull(project.ProjectDir);
Assert.NotNull(project.TargetFileName);

project.Build(additionalArgs: null);

var targetDir = Path.GetFullPath(Path.Combine(project.ProjectDir!, project.OutputPath!));
var targetPath = Path.Combine(targetDir, project.TargetFileName!);
Assert.True(File.Exists(targetPath), $"Expected build output at {targetPath}");
});
}

private void WithVerboseOutput(Action action)
{
var previousIsVerbose = Reporter.IsVerbose;
var previousPrefixOutput = Reporter.PrefixOutput;
Reporter.IsVerbose = true;
Reporter.PrefixOutput = true;
Reporter.SetStdOut(new TestOutputWriter(output));
try
{
action();
}
finally
{
Reporter.IsVerbose = previousIsVerbose;
Reporter.PrefixOutput = previousPrefixOutput;
Reporter.SetStdOut(Console.Out);
}
}

private sealed class TestOutputWriter(ITestOutputHelper output) : StringWriter
{
public override void WriteLine(string? value)
{
if (value != null)
{
output.WriteLine(value);
}
}
}
}
23 changes: 23 additions & 0 deletions test/dotnet-ef.Tests/TempDirectory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore.Tools;

internal class TempDirectory : IDisposable
{
public TempDirectory()
{
Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName());
Directory.CreateDirectory(Path);
}

public string Path { get; }

public void Dispose()
{
if (Directory.Exists(Path))
{
Directory.Delete(Path, recursive: true);
}
}
}
Loading