Skip to content

C# Autobuild misidentifies incompatible SDK-style projects #19258

Closed
@Arthri

Description

@Arthri

Given the following csproj,

<Project>
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>

Autobuild only looks at the root <Project> node and sees that it does not have an Sdk attribute, and subsequently incorrectly identifying that it is not compatible and switches to building using Mono. This way of writing SDK-style projects, specifically using <Import /> explicitly, is documented here https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2022#use-the-import-element-anywhere-in-your-project

I believe that the code which identifies whether a project is compatible is located here
https://github.com/github/codeql/blob/main/csharp/autobuilder/Semmle.Autobuild.Shared/Project.cs#L50

I have set up a repository which reproduces this issue https://github.com/Arthri/NonStdSdkAutobuild/

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions