egallagher
egallagher

Reputation: 73

Is there a way to detect the current SDK being used in a .targets MSBuild file?

In .NET, you can specify which .NET project SDK you would like to use by specifying the Sdk attribute on the top-level Project element:

<Project Sdk="Microsoft.NET.Web.Sdk">

I am writing a NuGet package and attempting to find an MSBuild property or item that saves off which SDK is being used. I am not having any luck in the official documentation nor when examining a build in the MSBuild Structured Log Viewer in finding one.

Is there an idiomatic way to identify which Sdk has been selected for a project in an MSBuild .targets file?

I would have expected a property like

$(MSBuildProjectSdkName) // "Microsoft.NET.Web.Sdk"

Upvotes: 7

Views: 866

Answers (1)

nvirth
nvirth

Reputation: 1751

The closest I've found using Rider IDE's Project Properties window:
Rider IDE's Project Properties window

This is in a project using the Microsoft.NET.Web.Sdk.
So it seems there are 3 SDK related properties set in a Web SDK project:

UsingMicrosoftNETSdk
UsingMicrosoftNETSdkRazor
UsingMicrosoftNETSdkWeb

I guess you can determine if the Web SDK is used with Condition=" '$(UsingMicrosoftNETSdkWeb)' == 'true' "

Upvotes: 8

Related Questions