Reputation: 4116
Is there a way in which I can determine with which dotnet SDK an assembly (targetting dotnet core) is built?
Up till now we didn't use a global.json to specify with which dotnet SDK to build our assemblies, meaning the latest SDK is used. We have recently switched to dotnet 3.1.x for new projects but still have a lot of projects that are targetting dotnet 2.1.x
I'm not sure what kind of subtle changes (or even bugs?) could be introduced when building a project targetting dotnet 2.1.x with dotnet 3.1.x SDK
To be sure we are going to use global.json (in orde to define which .NET Core SDK version is used when building). And, if possible, are going to check how many assemblies were already shipped that were build with a higher dotnet core SDK. Is it even possible?
Upvotes: 2
Views: 612
Reputation: 1499770
Note: there may be a simpler way of doing this, but I don't know it at the moment. I don't know of any way of determining it from an existing assembly.
When you build with the .NET Core SDK, a NETCoreSdkVersion
MSBuild property is set.
You could create a target with BeforeTargets="CoreCompile"
that generates source code including that build property, to add an assembly-level attribute (that you'd have to define yourself). This would be similar to how AssemblyInfo.g.cs
is generated already.
I'm afraid I don't have enough time to put together a complete example of it right now - but you can see an example of automated code generation here. That's part of a targets
directory in a NuGet package, so that code depending on that package gets the code generation automatically; you could do something like that, or if everything is in the same solution you could use a Directory.Build.targets
or similar.
Upvotes: 2