Skip to content

javiercn/tfmsamples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TFM exploration

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 a net8.0-browswer1.0 class library and calling dotnet test.

General steps to enable the TFM

  • 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>

Findings

  • 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.

Unexplored areas

  • All the investigation was command-line driven, haven't played through VS yet.

Potential improvements to the experience

  • 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).

List of scenarios with their description

01 - Standalone app

flowchart TD
subgraph Application
net8.0-browser1.0
end
Loading

02 - Standalone class library

flowchart TD
subgraph Library
net8.0-browser1.0
end
Loading

03 - Standalone multitargeting app

flowchart TD
subgraph Application
net8.0;net8.0-browser1.0
end
Loading

04 - Standalone multitargeting library

flowchart TD
subgraph Library
net8.0;net8.0-browser1.0
end
Loading

05 - Singletargeting app references singletargeting library

flowchart TD

subgraph Application
  net8browserapp["net8.0-browser1.0"]
end

subgraph Library
  net8.0-browser1.0lib["net8.0-browser1.0"]
end

Application-->Library
Loading

06 - Singletargeting app references singletargeting browser library

flowchart TD

subgraph Application
  net8app["net8.0"]
end

subgraph Library
  net8.0-browser1.0lib["net8.0-browser1.0"]
end

Application-->Library
Loading

07 - Singletargeting browser app references singletargeting library

flowchart TD

subgraph Application
  net8.0-browser1.0app["net8.0-browser1.0"]
end

subgraph Library
  net8.0lib["net8.0"]
end

Application-->Library
Loading

08 - Multitargeting app references multitargeting 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
Loading

09 - Multitargeting app references single targeting library

flowchart TD

subgraph Application
  net8app["net8.0"]
  net8browserapp["net8.0-browser1.0"]
end

subgraph Library
  net8.0lib["net8.0"]
end

Application-->Library
Loading

10 - Multitargeting app references single targeting library (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
Loading

11 - Single targeting app references multi targeting library

flowchart TD

subgraph Application
  net8app["net8.0"]
end

subgraph Library
  net8lib["net8.0"]
  net8.0browserlib["net8.0-browser1.0"]
end

Application-->Library
Loading

12 - Single targeting app references multi targeting library (browser)

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
Loading

Interesting scenarios

These are scenarios where I had to add additional attributes to the ProjectReference to get things working.

Scenario 10

06 - Single target app references single targeting library (browser)

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
Loading
  • 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.

10 - Multitargeting app references single targeting library (browser)

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
Loading
  • 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.

About

Samples demonstrating different combinations for the new browser TFM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published