Skip to content

Instantly share code, notes, and snippets.

@teneko
Last active August 3, 2020 02:49
Show Gist options
  • Save teneko/30cc3adc0649b773b36617b2cf1c6caf to your computer and use it in GitHub Desktop.
Save teneko/30cc3adc0649b773b36617b2cf1c6caf to your computer and use it in GitHub Desktop.
MSBuild/NuGet Playground
<!--
=====================================================
BuildEachTargetFramework
Builds project for each TargetFramework. It is called
from synthetic projects.
Target _GetTargetFrameworksOutput belongs to
https://github.com/NuGet/NuGet.Client/blob/c05f9afa9c2fcee7fbe10754521b3f6424bee128/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L98
=====================================================
-->
<Target Name="BuildEachTargetFramework2" DependsOnTargets="_GetTargetFrameworksOutput;AssignProjectConfiguration;_SplitProjectReferencesByFileExistence"
Condition="$(ExecutableProjectFullPath) != ''">
<MSBuild
Projects="%(ProjectReferenceWithConfiguration.Identity)"
Targets="_SetPackedExecutableProjectReferences"
ContinueOnError="true"
Properties="ProjectReferenceWithConfigurationIdentity=%(ProjectReferenceWithConfiguration.Identity)">
<Output TaskParameter="TargetOutputs" ItemName="ProjectReferenceWithConfiguration" />
</MSBuild>
<RemoveDuplicates Inputs="@(ProjectReferenceWithConfiguration)" />
<ItemGroup>
<ProjectReferenceWithConfiguration Remove="@(ProjectReferenceWithConfiguration)" Condition="%(FullPath) == $(SyntheticProjectFullPath)" />
</ItemGroup>
<ItemGroup>
<ProjectReferenceWithConfiguration Update="@(ProjectReferenceWithConfiguration)">
<PackExecutableChosenTargetEntry Condition="'%(PackedAsExecutableProjectWontBuilding)' == 'true'">_BuildPackExecutableSpecificNonBuildingProjectReference</PackExecutableChosenTargetEntry>
<PackExecutableChosenTargetEntry Condition="'%(PackedAsExecutableProjectWontBuilding)' != 'true'">_BuildPackExecutableSpecificProjectReference</PackExecutableChosenTargetEntry>
</ProjectReferenceWithConfiguration>
</ItemGroup>
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="%(ProjectReferenceWithConfiguration.PackExecutableChosenTargetEntry)"
Properties="PackExecutableSpecificProjectReference=%(ProjectReferenceWithConfiguration.FullPath)" />
</Target>
<!--
Uses _GetTargetFrameworksOutput of
https://github.com/NuGet/NuGet.Client/blob/c05f9afa9c2fcee7fbe10754521b3f6424bee128/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L98
-->
<MSBuild Projects="$(PackExecutableSpecificProjectReference)" Targets="_GetTargetFrameworksOutput">
<Output TaskParameter="TargetOutputs" ItemName="_TargetFrameworks" />
</MSBuild>
<Project InitialTargets="test">
<ItemDefinitionGroup>
<Test>
<A>a</A>
</Test>
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<Test>
<B>b</B>
</Test>
</ItemDefinitionGroup>
<ItemGroup>
<Test Include="One" />
</ItemGroup>
<Target Name="test">
<Message Text="ID: %(Test.Identity) A: %(Test.A) B: %(Test.B)" Importance="high" />
<!-- Results in "ID: One A: a B: b". -->
</Target>
</Project>
<Project>
<PropertyGroup>
<!--<TargetFramework>netstandard1.0</TargetFramework>-->
<IncludeBuildOutput>false</IncludeBuildOutput>
<NoPackageAnalysis>true</NoPackageAnalysis>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment