Skip to content

System.Web reference is dropped from @(Reference) when building with the dotnet CLI (Core MSBuild) #105

Description

@ehasis

Split out from #103 (item 1).

Summary

When a project that uses MSBuild.SDK.SystemWeb is built with dotnet build (Core MSBuild), the System.Web framework reference never reaches the compiler, so any use of System.Web.* types fails to compile — e.g. error BC30002: type 'System.Web.HttpApplication' is not defined / error CS0246. Building the same project with the full Visual Studio MSBuild works fine.

Details

The SDK contributes the reference here: src/MSBuild.SDK.SystemWeb.CommonFiles/Sdk/MSBuild.SDK.SystemWeb.Common.DefaultPackages.targets

<ItemGroup Condition="'$(ExcludeSDKDefaultPackages)'=='false'">
  ...
  <Reference Include="System.Web" />
</ItemGroup>

That file is imported at the top of Sdk.targets, i.e. before <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />.

Observed under Core MSBuild (dotnet):

  • Other default framework references (System, System.Core, System.Data, …) resolve from the v4.x reference assemblies and reach vbc/csc.
  • System.Web does not appear in @(Reference) at ResolveAssemblyReferences time, so it is never passed to the compiler.
  • A bare framework <Reference Include="System.Web" /> declared after the Microsoft.NET.Sdk targets import — or in the project body — does survive and resolve. So the drop is tied to declaring it before those targets, under Core MSBuild only.

Minimal repro

net48 project with <Project Sdk="MSBuild.SDK.SystemWeb/<ver>"> and a class that references System.Web.HttpApplication; a minimal web.config. dotnet build fails; msbuild (full VS) succeeds.

Open question (help wanted)

I have not yet pinned down the exact Microsoft.NET.Sdk target/logic that removes the pre-import reference under Core MSBuild — happy to dig further. If you (or anyone) recognize the mechanism, that would confirm the right fix. This is the "reference to the main Microsoft.NET.Sdk" you asked about.

Proposed fix

Re-declare System.Web after the Microsoft.NET.Sdk targets import, gated on '$(MSBuildRuntimeType)' == 'Core' so the full VS MSBuild keeps using the existing Common.DefaultPackages.targets reference and there is no duplicate (MSB3105).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions