bazel-contrib / bazel-contrib/rules_dotnet
bazel run for web sdk does not load appsettings.json
- Dominant language
- Starlark
- Stars
- 209
- Forks
- 98
- Avg merge
- 3h 59m
- Merged PRs (30d)
- 14
Description
I have modified this example slightly to print out the contents of the json file
Example:
https://github.com/bazel-contrib/rules_dotnet/blob/master/examples/aspnetcore/Program.cs
Modified code
```cs
// Program.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Data;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Reflection.Metadata;
using System.Runtime.InteropServices.Marshalling;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
Console.WriteLine("print log level");
Console.WriteLine(builder.Configuration["Logging:LogLevel:Default"]);
var app = builder.Build();
app.UseAuthorization();
app.MapControllers();
app.Run("http://localhost:8000");
```
If you run this with bazel like this:
```sh
cd examples
bazel run //aspnetcore:aspnetcore
```
then the second console.writeline will print an empty string. i.e.
```
INFO: Running command line: bazel-bin/aspnetcore/aspnetcore/net8.0/aspnetcore.dll.sh
print log level
```
Note the last line is blank.
if instead you run
```
cd examples/aspnetcore
dotnet run
```
It will correctly print the contents of the json file
```
$ dotnet run
print log level
Error
```
I can see the appsettings.json is copied into the output dir.
```
Target //aspnetcore:aspnetcore up-to-date:
bazel-bin/aspnetcore/aspnetcore/net8.0/aspnetcore.dll
bazel-bin/aspnetcore/aspnetcore/net8.0/aspnetcore.xml
bazel-bin/aspnetcore/aspnetcore/net8.0/appsettings.json
bazel-bin/aspnetcore/aspnetcore/net8.0/appsettings.Development.json
```
perhaps the shell script has the wrong working directory?
Contributor guide
Research direction
Start with examples/aspnetcore/Program.cs, appsettings.json, and the Bazel output for the generated aspnetcore.dll.sh launcher. Compare the working directory and configuration loading under bazel run with dotnet run. Done means the Bazel-launched example loads appsettings.json and prints Error for Logging:LogLevel:Default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100