Below is an exploration of different project combinations to asses what it takes to add the net8.0-browser TFM and exercising the most common operations (restore, build, pack, publish)
- For testing I have only tried making the test project
net8.0-browser1.0
, referencing anet8.0-browswer1.0
class library and calling dotnet test.
- Specify the platform with a version (net8.0-browswer1.0)
- Add the property
<TargetPlatformSupported>true</TargetPlatformSupported>
to a property group. - Add the version to the list of supported target platform versions:
<ItemGroup Condition="'$([MSBuild]::GetTargetPlatformIdentifier($(TargetFramework)))' == 'browser'"> <SdkSupportedTargetPlatformVersion Include="1.0" /> </ItemGroup>
- Was not able to just specify net8.0-browser
- Was not able to get rid of
warning CA1418: Version '1.0' is not valid for platform 'browser'. Do not use versions for this platform.
- I suspect this is a matter of "finding" the right "knob" on the SDK.
- All the investigation was command-line driven, haven't played through VS yet.
- Requirement to specify the target framework during publish when multitargeting:
- It would be great if we could select a "preferred" target framework for publish.
- Even better if this is respected by the VS UI.
- Nuget package installation:
- Select the target framework when installing a dependency (CLI and UI) and have nuget place it in the right itemgroup (or per platform .targets file).
flowchart TD
subgraph Application
net8.0-browser1.0
end
flowchart TD
subgraph Library
net8.0-browser1.0
end
flowchart TD
subgraph Application
net8.0;net8.0-browser1.0
end
flowchart TD
subgraph Library
net8.0;net8.0-browser1.0
end
flowchart TD
subgraph Application
net8browserapp["net8.0-browser1.0"]
end
subgraph Library
net8.0-browser1.0lib["net8.0-browser1.0"]
end
Application-->Library
flowchart TD
subgraph Application
net8app["net8.0"]
end
subgraph Library
net8.0-browser1.0lib["net8.0-browser1.0"]
end
Application-->Library
flowchart TD
subgraph Application
net8.0-browser1.0app["net8.0-browser1.0"]
end
subgraph Library
net8.0lib["net8.0"]
end
Application-->Library
flowchart TD
subgraph Application
net8app["net8.0"]
net8browserapp["net8.0-browser1.0"]
end
subgraph Library
net8.0lib["net8.0"]
net8.0-browser1.0lib["net8.0-browser1.0"]
end
Application-->Library
flowchart TD
subgraph Application
net8app["net8.0"]
net8browserapp["net8.0-browser1.0"]
end
subgraph Library
net8.0lib["net8.0"]
end
Application-->Library
flowchart TD
subgraph Application
net8app["net8.0"]
net8browserapp["net8.0-browser1.0"]
end
subgraph Library
net8.0browserlib["net8.0-browser1.0"]
end
Application-->Library
flowchart TD
subgraph Application
net8app["net8.0"]
end
subgraph Library
net8lib["net8.0"]
net8.0browserlib["net8.0-browser1.0"]
end
Application-->Library
flowchart TD
subgraph Application
net8-browserapp["net8.0-browser1.0"]
end
subgraph Library
net8lib["net8.0"]
net8.0browserlib["net8.0-browser1.0"]
end
Application-->Library
These are scenarios where I had to add additional attributes to the ProjectReference
to get things working.
The app targets net8.0 and the library targets net8.0-browser
flowchart TD
subgraph Application
net8app["net8.0"]
end
subgraph Library
net8.0-browser1.0lib["net8.0-browser1.0"]
end
Application-->Library
-
Was able to make the project reference work by adding a couple of properties to it:
<ProjectReference Include="..\singletargetclasslib\singletargetclasslib.csproj" SkipGetTargetFrameworkProperties="true" ReferenceOutputAssembly="false" />
-
This effectively disabled referencing the output assembly but maintained the reference, so I suspect static web assets will work just fine in this scenario.
-
The canonical example for this scenario is
Web App
"hosts"Webassembly App
.
App multitargets but the library only targets the browser
flowchart TD
subgraph Application
net8app["net8.0"]
net8browserapp["net8.0-browser1.0"]
end
subgraph Library
net8.0browserlib["net8.0-browser1.0"]
end
Application-->Library
- Had to add the project reference to the library conditionally:
<ItemGroup Condition="'$([MSBuild]::GetTargetPlatformIdentifier($(TargetFramework)))' == 'browser'"> <ProjectReference Include="..\singletargetclasslib\singletargetclasslib.csproj" /> </ItemGroup>
- Alternatively, could have done the same thing as in scenario 06 conditionally to the TFM being built not being the browser TFM.