Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example of how to do multi-tfm publishing without SDK support #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

baronfel
Copy link

@baronfel baronfel commented Sep 8, 2023

No description provided.

Copy link
Author

@baronfel baronfel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes on what's going on here.

@@ -0,0 +1,31 @@
<Project>
<Target
Name="PublishSamples"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

putting this target in every project (via D.B.targets) means that calling the target at the solution-level Just Works (thanks to solution file's traversal targets mechanism).

<Project>
<Target
Name="PublishSamples"
Condition="'$(IsSample)' == 'true'">
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we don't want this to fire for the actual library (which is why the Samples now have a D.B.props that adds this property).

Comment on lines +7 to +9
<_IsMultiTargetTfm Condition="'$(TargetFrameworks)' != ''and '$(TargetFramework)' == ''">true</_IsMultiTargetTfm>
<_IsSingleTargetTfmNoRids Condition="'$(TargetFramework)' != '' and '$(RuntimeIdentifiers)' == ''">true</_IsSingleTargetTfmNoRids>
<_IsSingleTargetAndMultiRid Condition="'$(TargetFramework)' != '' and '$(RuntimeIdentifiers)' != ''">true</_IsSingleTargetAndMultiRid>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK (or MSBuild) could provide helper properties like this to make Conditions easier for authors.

Comment on lines +12 to +17
<ItemGroup Condition="'$(_IsMultiTargetTfm)' == 'true'">
<_TFMItems Include="$(TargetFrameworks)" />
<_SingleSamplePublish
Include="$(MSBuildProjectFullPath)"
AdditionalProperties="TargetFramework=%(_TFMItems.Identity);PublishDir=$(ArtifactsRoot)$(MSBuildProjectName)/%(_TFMItems.Identity)" />
</ItemGroup>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have multiple TFMs, then we want to Publish the project multiple times - once for each TFM. And since we need to deduplicate the published outputs, we add the TFM onto the outputs directory here. This logic is something very much like what the SDK might do - but for some publish targets like Containers, more customization might be needed (as well as some kind of post-TFMs-published hook).

Comment on lines +20 to +24
<ItemGroup Condition="'$(_IsSingleTargetTfm)' == 'true'">
<_SingleSamplePublish
Include="$(MSBuildProjectFullPath)"
AdditionalProperties="PublishDir=$(ArtifactsRoot)$(MSBuildProjectName)/$(TargetFramework)" />
</ItemGroup>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single TFM is similarly simple - just build this project once, specifying only the property that's needed.

Comment on lines +26 to +29
<MSBuild
Projects="@(_SingleSamplePublish)"
Targets="Publish"
BuildInParallel="true" />
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we've arranged our work to be done, fire it all off in parallel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant