-
Notifications
You must be signed in to change notification settings - Fork 17
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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" |
There was a problem hiding this comment.
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'"> |
There was a problem hiding this comment.
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).
<_IsMultiTargetTfm Condition="'$(TargetFrameworks)' != ''and '$(TargetFramework)' == ''">true</_IsMultiTargetTfm> | ||
<_IsSingleTargetTfmNoRids Condition="'$(TargetFramework)' != '' and '$(RuntimeIdentifiers)' == ''">true</_IsSingleTargetTfmNoRids> | ||
<_IsSingleTargetAndMultiRid Condition="'$(TargetFramework)' != '' and '$(RuntimeIdentifiers)' != ''">true</_IsSingleTargetAndMultiRid> |
There was a problem hiding this comment.
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.
<ItemGroup Condition="'$(_IsMultiTargetTfm)' == 'true'"> | ||
<_TFMItems Include="$(TargetFrameworks)" /> | ||
<_SingleSamplePublish | ||
Include="$(MSBuildProjectFullPath)" | ||
AdditionalProperties="TargetFramework=%(_TFMItems.Identity);PublishDir=$(ArtifactsRoot)$(MSBuildProjectName)/%(_TFMItems.Identity)" /> | ||
</ItemGroup> |
There was a problem hiding this comment.
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).
<ItemGroup Condition="'$(_IsSingleTargetTfm)' == 'true'"> | ||
<_SingleSamplePublish | ||
Include="$(MSBuildProjectFullPath)" | ||
AdditionalProperties="PublishDir=$(ArtifactsRoot)$(MSBuildProjectName)/$(TargetFramework)" /> | ||
</ItemGroup> |
There was a problem hiding this comment.
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.
<MSBuild | ||
Projects="@(_SingleSamplePublish)" | ||
Targets="Publish" | ||
BuildInParallel="true" /> |
There was a problem hiding this comment.
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.
No description provided.