-
Notifications
You must be signed in to change notification settings - Fork 855
Description
Description
The Microsoft.Extensions.AmbientMetadata.Application package targets and supports the standard TFMs as well as netstandard2.0 and net462.
The Microsoft.Extensions.AmbientMetadata.Build package does not include these extra TFMs and cannot be used on those platforms.
I don't see any specific code that would prevent it working on those additional platforms.
Manually adding BuildMetadata.cs and BuildMetadataServiceCollectionExtensions.cs to a netstandard2.0 project worked (except the embedded version of Throw.IfNull) so I think it should just work by changing the TFMs for this package.
Reproduction Steps
Create a netstandard2.0 project and add references to Microsoft.Extensions.AmbientMetadata.Application and Microsoft.Extensions.AmbientMetadata.Build.
Try and reference IOptions<ApplicationMetadata>- Success.
Try and reference IOptions<BuildMetadata> - Fails.
Expected behavior
The following code snippet should compile in a netstandard2.0 class library or a net4x application.
public static void LogAmbient(IServiceProvider serviceProvider)
{
var logger = serviceProvider.GetRequiredService<ILoggerFactory>().CreateLogger("Ambient");
var application = serviceProvider.GetRequiredService<IOptions<ApplicationMetadata>>().Value;
var build = serviceProvider.GetRequiredService<IOptions<BuildMetadata>>().Value;
logger.LogInformation("Application {Name} {Version}", application.ApplicationName, application.BuildVersion);
logger.LogInformation("Build Information {Number} {Id}", build.BuildNumber, build.BuildId);
logger.LogInformation("Source {Branch}/{Version}", build.SourceBranchName, build.SourceVersion);
}Actual behavior
Code does not compile unless targeting net8.0, net9.0, or net10.0.
BuildMetadata type does not exist on other platforms (ApplicationMetadata does exist)
Regression?
No response
Known Workarounds
It is almost possible to get this to work by embedding the types mentioned and forcing the Microsoft.Extensions.AmbientMetadata.Build package to be private to avoid pulling it into a net10.0 project.
Alternatively, multitargeting with #if !NET clauses around the code can also work but either solution is not ideal.
Configuration
Not really applicable, but netstandard2.0.
Using NET10 SDK and referencing the classlibrary from both a net10.0 project and a net481 project.
Other information
Line 7 in 00b5638
| <TargetFrameworks>$(NetCoreTargetFrameworks)</TargetFrameworks> |
vs
Line 4 in 00b5638
| <TargetFrameworks>$(NetCoreTargetFrameworks);netstandard2.0;net462</TargetFrameworks> |