Skip to content

Commit

Permalink
WIP ASP.NET
Browse files Browse the repository at this point in the history
  • Loading branch information
tareqimbasher committed Dec 7, 2023
1 parent dc4259b commit a04c62b
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,5 +506,14 @@ export const snippets = {
"}$0"
],
description: "create xunit test method"
},
"Web App (ASP.NET)": {
prefix: "webapp",
body: [
"var app = WebApplication.CreateBuilder().Build();",
"app.UseWelcomePage();",
"await app.RunAsync(\"http://localhost:${0:5678}\");",
],
description: "create xunit test method"
}
}
3 changes: 3 additions & 0 deletions src/Core/NetPad.Compilation/SystemAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ private static HashSet<string> GetReferenceAssemblyLocationsFromDotNetRoot(IDotN
}

return Directory.GetFiles(assembliesDirectory, "*.dll")
.Union(
Directory.GetFiles("/opt/dotnet/packs/Microsoft.AspNetCore.App.Ref/7.0.10/ref/net7.0", "*.dll")
)
.Where(a => !a.Contains("VisualBasic"))
.ToHashSet();
}
Expand Down
10 changes: 8 additions & 2 deletions src/Core/NetPad.Domain/DotNet/DotNetCSharpProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public DotNetCSharpProject(
/// <param name="targetDotNetFrameworkVersion">The .NET framework to target.</param>
/// <param name="outputType">The output type of the project.</param>
/// <param name="deleteExisting">If true, will delete the project directory if it already exists on disk.</param>
public virtual async Task CreateAsync(DotNetFrameworkVersion targetDotNetFrameworkVersion, ProjectOutputType outputType, bool deleteExisting = false)
public virtual async Task CreateAsync(
DotNetFrameworkVersion targetDotNetFrameworkVersion,
ProjectOutputType outputType,
ProjectSdkType sdkType = ProjectSdkType.NetCoreApp,
bool deleteExisting = false)
{
if (deleteExisting)
{
Expand All @@ -84,7 +88,9 @@ public virtual async Task CreateAsync(DotNetFrameworkVersion targetDotNetFramewo

string dotnetOutputType = outputType == ProjectOutputType.Executable ? "Exe" : "Library";

string xml = $@"<Project Sdk=""Microsoft.NET.Sdk"">
var sdk = sdkType == ProjectSdkType.NetCoreApp ? "Microsoft.NET.Sdk" : "Microsoft.NET.Sdk.Web";

string xml = $@"<Project Sdk=""{sdk}"">
<PropertyGroup>
<OutputType>{dotnetOutputType}</OutputType>
Expand Down
6 changes: 6 additions & 0 deletions src/Core/NetPad.Domain/DotNet/ProjectOutputType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ public enum ProjectOutputType
Library,
Executable
}

public enum ProjectSdkType
{
NetCoreApp,
AspNetCoreApp
}
13 changes: 12 additions & 1 deletion src/Core/NetPad.Domain/Scripts/ScriptConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ public static class ScriptConfigDefaults
//"System.Transactions",
"System.Xml",
"System.Xml.Linq",
"System.Xml.XPath"
"System.Xml.XPath",


"System.Net.Http.Json",
"Microsoft.AspNetCore.Builder",
"Microsoft.AspNetCore.Hosting",
"Microsoft.AspNetCore.Http",
"Microsoft.AspNetCore.Routing",
"Microsoft.Extensions.Configuration",
"Microsoft.Extensions.DependencyInjection",
"Microsoft.Extensions.Hosting",
"Microsoft.Extensions.Logging",
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private string GenerateRuntimeConfigFileContents(RunDependencies runDependencies
""runtimeOptions"": {{
""tfm"": ""{tfm}"",
""framework"": {{
""name"": ""Microsoft.NETCore.App"",
""name"": ""Microsoft.AspNetCore.App"",
""version"": ""{runtimeVersion}""
}},
""rollForward"": ""Minor"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public EntityFrameworkDatabaseScaffolder(

public async Task<ScaffoldedDatabaseModel> ScaffoldAsync()
{
await _project.CreateAsync(_targetFrameworkVersion, ProjectOutputType.Library, true);
await _project.CreateAsync(_targetFrameworkVersion, ProjectOutputType.Library, ProjectSdkType.NetCoreApp, true);

try
{
Expand Down
7 changes: 2 additions & 5 deletions src/Plugins/NetPad.Plugins.OmniSharp/ScriptProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ public ScriptProject(
public string UserProgramFilePath { get; }
public string DataConnectionProgramFilePath { get; }

public override async Task CreateAsync(DotNetFrameworkVersion targetDotNetFrameworkVersion, ProjectOutputType outputType, bool deleteExisting = false)
public override async Task CreateAsync(DotNetFrameworkVersion targetDotNetFrameworkVersion, ProjectOutputType outputType, ProjectSdkType sdkType, bool deleteExisting = false)
{
await base.CreateAsync(targetDotNetFrameworkVersion, outputType, deleteExisting);

var domainAssembly = typeof(IOutputWriter<>).Assembly;
await AddAssemblyFileReferenceAsync(new AssemblyFileReference(domainAssembly.Location));
await base.CreateAsync(targetDotNetFrameworkVersion, outputType, sdkType, deleteExisting);
await AddReferencesAsync(Script.Config.References);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public async Task<bool> StartAsync()
await Project.CreateAsync(
_environment.Script.Config.TargetFrameworkVersion,
ProjectOutputType.Executable,
ProjectSdkType.AspNetCoreApp,
true);

await Project.SetProjectPropertyAsync("AllowUnsafeBlocks", "true");
Expand Down

0 comments on commit a04c62b

Please sign in to comment.