-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project> | ||
<Target | ||
Name="PublishSamples" | ||
Condition="'$(IsSample)' == 'true'"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
<PropertyGroup> | ||
<ArtifactsRoot>$(MSBuildThisFileDirectory)/artifacts/</ArtifactsRoot> | ||
<_IsMultiTargetTfm Condition="'$(TargetFrameworks)' != ''and '$(TargetFramework)' == ''">true</_IsMultiTargetTfm> | ||
<_IsSingleTargetTfmNoRids Condition="'$(TargetFramework)' != '' and '$(RuntimeIdentifiers)' == ''">true</_IsSingleTargetTfmNoRids> | ||
<_IsSingleTargetAndMultiRid Condition="'$(TargetFramework)' != '' and '$(RuntimeIdentifiers)' != ''">true</_IsSingleTargetAndMultiRid> | ||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
</PropertyGroup> | ||
<!-- TFMs but no TF -> multitarget, making samples for each TFM --> | ||
<ItemGroup Condition="'$(_IsMultiTargetTfm)' == 'true'"> | ||
<_TFMItems Include="$(TargetFrameworks)" /> | ||
<_SingleSamplePublish | ||
Include="$(MSBuildProjectFullPath)" | ||
AdditionalProperties="TargetFramework=%(_TFMItems.Identity);PublishDir=$(ArtifactsRoot)$(MSBuildProjectName)/%(_TFMItems.Identity)" /> | ||
</ItemGroup> | ||
Comment on lines
+12
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
|
||
<!-- TF but no TFMs -> single sample (aka the default pathway) up until now --> | ||
<ItemGroup Condition="'$(_IsSingleTargetTfm)' == 'true'"> | ||
<_SingleSamplePublish | ||
Include="$(MSBuildProjectFullPath)" | ||
AdditionalProperties="PublishDir=$(ArtifactsRoot)$(MSBuildProjectName)/$(TargetFramework)" /> | ||
</ItemGroup> | ||
Comment on lines
+20
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" /> | ||
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
</Target> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<IsSample>true</IsSample> | ||
</PropertyGroup> | ||
|
||
<Import Project="../Directory.Build.props" /> | ||
</Project> |
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).