Skip to content

Commit 3a6f58b

Browse files
committed
get closer to successfully building
1 parent 796e760 commit 3a6f58b

File tree

10 files changed

+46
-558
lines changed

10 files changed

+46
-558
lines changed

src/Cli/Microsoft.DotNet.FileBasedPrograms/AppDirectiveHelpers.cs

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,10 @@ public sealed class Project(in ParseInfo info) : Named(info)
476476
}
477477
else if (!File.Exists(resolvedProjectPath))
478478
{
479-
throw new GracefulException(FileBasedProgramsResources.CouldNotFindProjectOrDirectory, resolvedProjectPath);
479+
throw new GracefulExceptionDELETEME(FileBasedProgramsResources.CouldNotFindProjectOrDirectory, resolvedProjectPath);
480480
}
481481
}
482-
catch (GracefulException e)
482+
catch (GracefulExceptionDELETEME e)
483483
{
484484
context.Diagnostics.AddError(context.SourceFile, context.Info.Span, string.Format(FileBasedProgramsResources.InvalidProjectDirective, e.Message), e);
485485
}
@@ -499,25 +499,25 @@ public static FileInfo GetProjectFileFromDirectory(string projectDirectory)
499499
}
500500
catch (ArgumentException)
501501
{
502-
throw new GracefulException(FileBasedProgramsResources.CouldNotFindProjectOrDirectory, projectDirectory);
502+
throw new GracefulExceptionDELETEME(FileBasedProgramsResources.CouldNotFindProjectOrDirectory, projectDirectory);
503503
}
504504

505505
if (!dir.Exists)
506506
{
507-
throw new GracefulException(FileBasedProgramsResources.CouldNotFindProjectOrDirectory, projectDirectory);
507+
throw new GracefulExceptionDELETEME(FileBasedProgramsResources.CouldNotFindProjectOrDirectory, projectDirectory);
508508
}
509509

510510
FileInfo[] files = dir.GetFiles("*proj");
511511
if (files.Length == 0)
512512
{
513-
throw new GracefulException(
513+
throw new GracefulExceptionDELETEME(
514514
FileBasedProgramsResources.CouldNotFindAnyProjectInDirectory,
515515
projectDirectory);
516516
}
517517

518518
if (files.Length > 1)
519519
{
520-
throw new GracefulException(FileBasedProgramsResources.MoreThanOneProjectInDirectory, projectDirectory);
520+
throw new GracefulExceptionDELETEME(FileBasedProgramsResources.MoreThanOneProjectInDirectory, projectDirectory);
521521
}
522522

523523
return files.First();
@@ -578,7 +578,7 @@ internal readonly struct DiagnosticBag
578578
public bool IgnoreDiagnostics { get; private init; }
579579

580580
/// <summary>
581-
/// If <see langword="null"/> and <see cref="IgnoreDiagnostics"/> is <see langword="false"/>, the first diagnostic is thrown as <see cref="GracefulException"/>.
581+
/// If <see langword="null"/> and <see cref="IgnoreDiagnostics"/> is <see langword="false"/>, the first diagnostic is thrown as <see cref="GracefulExceptionDELETEME"/>.
582582
/// </summary>
583583
public ImmutableArray<SimpleDiagnostic>.Builder? Builder { get; private init; }
584584

@@ -595,7 +595,7 @@ public void AddError(SourceFile sourceFile, TextSpan span, string message, Excep
595595
}
596596
else if (!IgnoreDiagnostics)
597597
{
598-
throw new GracefulException($"{sourceFile.GetLocationString(span)}: {FileBasedProgramsResources.DirectiveError}: {message}", inner);
598+
throw new GracefulExceptionDELETEME($"{sourceFile.GetLocationString(span)}: {FileBasedProgramsResources.DirectiveError}: {message}", inner);
599599
}
600600
}
601601

@@ -605,24 +605,3 @@ public void AddError(SourceFile sourceFile, TextSpan span, string message, Excep
605605
return default;
606606
}
607607
}
608-
609-
// TODO: Remove usage of GracefulException out of shared package.
610-
// Use as some kind of wrapper over in dotnet cli side to preserve behavior there.
611-
internal class GracefulException : Exception
612-
{
613-
public GracefulException()
614-
{
615-
}
616-
617-
public GracefulException(string? message) : base(message)
618-
{
619-
}
620-
621-
public GracefulException(string? message, string? todo2) : base(message)
622-
{
623-
}
624-
625-
public GracefulException(string? message, Exception? innerException) : base(message, innerException)
626-
{
627-
}
628-
}

src/Cli/Microsoft.DotNet.FileBasedPrograms/ExternalHelpers.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,26 @@ public static string GetRelativePath(string relativeTo, string path)
4141
}
4242

4343
#endif
44+
45+
// TODO: this is tricky. dotnet cli includes this type via ProjectReference to Cli.Utils.
46+
// But it's not reasonable to reference that project from Roslyn.
47+
// We should probably avoid using this type in the source package.
48+
// But currently there is a significant behavioral need and number of callers who are catching GracefulException.
49+
internal class GracefulExceptionDELETEME : Exception
50+
{
51+
public GracefulExceptionDELETEME()
52+
{
53+
}
54+
55+
public GracefulExceptionDELETEME(string? message) : base(message)
56+
{
57+
}
58+
59+
public GracefulExceptionDELETEME(string? message, string? todo2) : base(message)
60+
{
61+
}
62+
63+
public GracefulExceptionDELETEME(string? message, Exception? innerException) : base(message, innerException)
64+
{
65+
}
66+
}

src/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.DotNet.Cli.Commands.Run;
1212
using Microsoft.DotNet.Cli.Extensions;
1313
using Microsoft.DotNet.Cli.Utils;
14+
using Microsoft.DotNet.FileBasedPrograms;
1415
using NuGet.ProjectModel;
1516

1617
namespace Microsoft.DotNet.Cli.Commands.Package.Add;

src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.DotNet.Cli.Commands.Run;
88
using Microsoft.DotNet.Cli.Extensions;
99
using Microsoft.DotNet.Cli.Utils;
10+
using Microsoft.DotNet.FileBasedPrograms;
1011

1112
namespace Microsoft.DotNet.Cli.Commands.Package.Remove;
1213

src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.Build.Evaluation;
77
using Microsoft.DotNet.Cli.Commands.Run;
88
using Microsoft.DotNet.Cli.Utils;
9+
using Microsoft.DotNet.FileBasedPrograms;
910
using Microsoft.TemplateEngine.Cli.Commands;
1011

1112
namespace Microsoft.DotNet.Cli.Commands.Project.Convert;
@@ -29,7 +30,7 @@ public override int Execute()
2930

3031
// Find directives (this can fail, so do this before creating the target directory).
3132
var sourceFile = SourceFile.Load(file);
32-
var directives = VirtualProjectBuildingCommand.FindDirectives(sourceFile, reportAllErrors: !_force, DiagnosticBag.ThrowOnFirst());
33+
var directives = AppDirectiveHelpers.FindDirectives(sourceFile, reportAllErrors: !_force, DiagnosticBag.ThrowOnFirst());
3334

3435
// Find other items to copy over, e.g., default Content items like JSON files in Web apps.
3536
var includeItems = FindIncludedItems().ToList();

src/Cli/dotnet/Commands/Run/Api/RunApiCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text.Json;
99
using System.Text.Json.Serialization;
1010
using Microsoft.DotNet.Cli.Utils;
11+
using Microsoft.DotNet.FileBasedPrograms;
1112

1213
namespace Microsoft.DotNet.Cli.Commands.Run.Api;
1314

@@ -64,7 +65,7 @@ public sealed class GetProject : RunApiInput
6465
public override RunApiOutput Execute()
6566
{
6667
var sourceFile = SourceFile.Load(EntryPointFileFullPath);
67-
var directives = VirtualProjectBuildingCommand.FindDirectives(sourceFile, reportAllErrors: true, DiagnosticBag.Collect(out var diagnostics));
68+
var directives = AppDirectiveHelpers.FindDirectives(sourceFile, reportAllErrors: true, DiagnosticBag.Collect(out var diagnostics));
6869
string artifactsPath = ArtifactsPath ?? VirtualProjectBuildingCommand.GetArtifactsPath(EntryPointFileFullPath);
6970

7071
var csprojWriter = new StringWriter();
@@ -160,6 +161,9 @@ public sealed class RunCommand : RunApiOutput
160161
}
161162
}
162163

164+
// TODO: getting the following error, which is not suppressible with pragma.
165+
// error SYSLIB1225: The type 'Encoding' includes the ref like property, field or constructor parameter 'Preamble'. No source code will be generated for the property, field or constructor. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1225)
166+
// I have no idea how the type 'Encoding' is ending up getting used as a result of my change.
163167
[JsonSerializable(typeof(RunApiInput))]
164168
[JsonSerializable(typeof(RunApiOutput))]
165169
internal partial class RunFileApiJsonSerializerContext : JsonSerializerContext;

src/Cli/dotnet/Commands/Run/FileBasedAppSourceEditor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.CodeAnalysis.CSharp;
88
using Microsoft.CodeAnalysis.CSharp.Syntax;
99
using Microsoft.CodeAnalysis.Text;
10+
using Microsoft.DotNet.FileBasedPrograms;
1011

1112
namespace Microsoft.DotNet.Cli.Commands.Run;
1213

@@ -33,7 +34,7 @@ public ImmutableArray<CSharpDirective> Directives
3334
{
3435
if (field.IsDefault)
3536
{
36-
field = VirtualProjectBuildingCommand.FindDirectives(SourceFile, reportAllErrors: false, DiagnosticBag.Ignore());
37+
field = AppDirectiveHelpers.FindDirectives(SourceFile, reportAllErrors: false, DiagnosticBag.Ignore());
3738
Debug.Assert(!field.IsDefault);
3839
}
3940

@@ -116,7 +117,7 @@ private TextChange DetermineAddChange(CSharpDirective directive)
116117
// Otherwise, we will add the directive to the top of the file.
117118
int start = 0;
118119

119-
var tokenizer = VirtualProjectBuildingCommand.CreateTokenizer(SourceFile.Text);
120+
var tokenizer = AppDirectiveHelpers.CreateTokenizer(SourceFile.Text);
120121
var result = tokenizer.ParseNextToken();
121122
var leadingTrivia = result.Token.LeadingTrivia;
122123

src/Cli/dotnet/Commands/Run/RunTelemetry.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.Build.Execution;
77
using Microsoft.DotNet.Cli.Commands.Run.LaunchSettings;
88
using Microsoft.DotNet.Cli.Utils;
9+
using Microsoft.DotNet.FileBasedPrograms;
910

1011
namespace Microsoft.DotNet.Cli.Commands.Run;
1112

0 commit comments

Comments
 (0)