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).
Split out from #103 (item 1).
Summary
When a project that uses
MSBuild.SDK.SystemWebis built withdotnet build(Core MSBuild), theSystem.Webframework reference never reaches the compiler, so any use ofSystem.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.targetsThat 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):System,System.Core,System.Data, …) resolve from the v4.x reference assemblies and reachvbc/csc.System.Webdoes not appear in@(Reference)atResolveAssemblyReferencestime, so it is never passed to the compiler.<Reference Include="System.Web" />declared after theMicrosoft.NET.Sdktargets 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
net48project with<Project Sdk="MSBuild.SDK.SystemWeb/<ver>">and a class that referencesSystem.Web.HttpApplication; a minimalweb.config.dotnet buildfails;msbuild(full VS) succeeds.Open question (help wanted)
I have not yet pinned down the exact
Microsoft.NET.Sdktarget/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 mainMicrosoft.NET.Sdk" you asked about.Proposed fix
Re-declare
System.Webafter theMicrosoft.NET.Sdktargets import, gated on'$(MSBuildRuntimeType)' == 'Core'so the full VS MSBuild keeps using the existingCommon.DefaultPackages.targetsreference and there is no duplicate (MSB3105).