WeihanLi / dotnet-exec

dotnet execute with custom entry point, another dotnet run without project file
Apache License 2.0
43 stars 4 forks source link

unexpected compile error #6

Open WeihanLi opened 1 year ago

WeihanLi commented 1 year ago
dotnet-exec "https://github.com/WeihanLi/SamplesInPractice/blob/56dda58920fa9921dad50fde4a8333581541cbd2/BalabalaSample/CorrelationIdSample.cs" --project "https://github.com/WeihanLi/SamplesInPractice/blob/56dda58920fa9921dad50fde4a8333581541cbd2/BalabalaSample/BalabalaSample.csproj" --wide false --debug
fail: dotnet-exec[0]
      Compile error:
      (24,40): error CS1929: 'ILoggingBuilder' does not contain a definition for 'AddSerilog' and the best extension method overload 'SerilogLoggerExtensions.AddSerilog(ILoggerFactory, ILogger?, bool)' requires a receiver of type 'Microsoft.Extensions.Logging.ILoggerFactory'

Version: 0.14.0+60527bb786298d0a812968d5129b802c38bf12ef

WeihanLi commented 1 year ago

Minimal sample to reproduce

// reference: nuget:WeihanLi.Common.Logging.Serilog

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WeihanLi.Common.Logging.Serilog;

namespace BalabalaSample;

public class Issue06Sample
{
    public static async Task MainTest()
    {
        var serviceCollection = new ServiceCollection()
                .AddLogging(builder => builder.AddSerilog())
            ;
        await using var provider = serviceCollection.BuildServiceProvider();
        provider.GetRequiredService<ILoggerFactory>()
            .CreateLogger("test")
            .LogInformation("Hello 1234");;
    }
}
WeihanLi commented 1 year ago

Works well in https://github.com/WeihanLi/SamplesInPractice/blob/82b843cb790bc8c3e565fc8980fd38c58dee5a96/RoslynSample/Program.cs

WeihanLi commented 1 year ago

Seemed it relates to the Microsoft.Extensions.Http package reference, it works when removing the Microsoft.Extensions.Http package reference, see commit https://github.com/WeihanLi/dotnet-exec/commit/a1dd0b5b39f882618e79def1591c7ce93fbca931

image

Created an issue on roslyn issues https://github.com/dotnet/sdk/issues/31691