Skip to content

Commit

Permalink
Merge pull request #92 from onovotny/reference-assms
Browse files Browse the repository at this point in the history
Reference assms
  • Loading branch information
Oren Novotny authored Jul 9, 2018
2 parents 4730e97 + d812535 commit 321123e
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 7 deletions.
14 changes: 14 additions & 0 deletions MSBuild.Sdk.Extras.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfAppUsingSdk", "Tests\Wpf
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClasslibWithNuGetSdkRef", "Tests\ClasslibWithNuGetSdkRef\ClasslibWithNuGetSdkRef.csproj", "{96E4CC91-6E55-4650-BA58-D6D1EF138EE2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClasslibraryAsSdk.Ref", "Tests\ClasslibraryAsSdk.Ref\ClasslibraryAsSdk.Ref.csproj", "{C2EE161F-0521-47F7-BE2D-0B55CA8B3C53}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Classlibrary.Ref", "Tests\Classlibrary.Ref\Classlibrary.Ref.csproj", "{2760D19C-F00A-40C4-B8DF-F28249E284FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -67,6 +71,14 @@ Global
{96E4CC91-6E55-4650-BA58-D6D1EF138EE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96E4CC91-6E55-4650-BA58-D6D1EF138EE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96E4CC91-6E55-4650-BA58-D6D1EF138EE2}.Release|Any CPU.Build.0 = Release|Any CPU
{C2EE161F-0521-47F7-BE2D-0B55CA8B3C53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2EE161F-0521-47F7-BE2D-0B55CA8B3C53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2EE161F-0521-47F7-BE2D-0B55CA8B3C53}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2EE161F-0521-47F7-BE2D-0B55CA8B3C53}.Release|Any CPU.Build.0 = Release|Any CPU
{2760D19C-F00A-40C4-B8DF-F28249E284FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2760D19C-F00A-40C4-B8DF-F28249E284FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2760D19C-F00A-40C4-B8DF-F28249E284FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2760D19C-F00A-40C4-B8DF-F28249E284FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -79,6 +91,8 @@ Global
{3B80BC9F-47DE-44EB-BCEE-798B6EE29F8D} = {26026DB4-DD68-43BF-8858-15AD2016C0B2}
{935E6481-E537-454F-B3C0-EF20C2AC2839} = {26026DB4-DD68-43BF-8858-15AD2016C0B2}
{96E4CC91-6E55-4650-BA58-D6D1EF138EE2} = {26026DB4-DD68-43BF-8858-15AD2016C0B2}
{C2EE161F-0521-47F7-BE2D-0B55CA8B3C53} = {26026DB4-DD68-43BF-8858-15AD2016C0B2}
{2760D19C-F00A-40C4-B8DF-F28249E284FE} = {26026DB4-DD68-43BF-8858-15AD2016C0B2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93349570-79D8-4F89-8E78-C66401620727}
Expand Down
2 changes: 2 additions & 0 deletions Source/MSBuild.Sdk.Extras/Build/Core.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<IsMultiTargetingBuild>true</IsMultiTargetingBuild>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)ReferenceAssembly.targets"/>

<ImportGroup Condition="'$(IsMultiTargetingBuild)' != 'true'">
<Import Project="$(MSBuildThisFileDirectory)Inference.targets"
Condition="'$(TargetFramework)' != '' AND !($(TargetFramework.Contains(',')) OR $(TargetFramework.Contains(';')))"/>
Expand Down
140 changes: 140 additions & 0 deletions Source/MSBuild.Sdk.Extras/Build/ReferenceAssembly.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<PropertyGroup>
<!-- Default is not a reference assembly -->
<ExtrasIsReferenceAssembly Condition="'$(ExtrasIsReferenceAssembly)' == ''">false</ExtrasIsReferenceAssembly>
</PropertyGroup>


<PropertyGroup Condition="'$(ExtrasIsReferenceAssembly)' == 'true'">
<DefineConstants Condition=" '$(_SdkLanguageSourceName)' != 'VisualBasic' ">$(DefineConstants);REFERENCE_ASSEMBLY</DefineConstants>
<DefineConstants Condition=" '$(_SdkLanguageSourceName)' == 'VisualBasic' ">$(DefineConstants),REFERENCE_ASSEMBLY=-1</DefineConstants>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<!-- Ref Assms should be determinisitc and not packable, but allow user override -->
<Deterministic Condition="'$(Deterministic)' == ''">true</Deterministic>
<IsPackable Condition="'$(IsPackable)' == ''">false</IsPackable>
</PropertyGroup>


<ItemDefinitionGroup>
<ReferenceAssemblyProjectReference>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<GlobalPropertiesToRemove>TargetFramework;RuntimeIdentifier</GlobalPropertiesToRemove>
</ReferenceAssemblyProjectReference>
</ItemDefinitionGroup>

<!-- This target is called by the source project into the reference assembly project to get the reference assembly output items -->
<Target Name="_SdkGetReferenceAssemblies" DependsOnTargets="Build" Returns="@(ReferenceAssembliesOutput)">
<ItemGroup>
<ReferenceAssembliesOutput Include="@(IntermediateRefAssembly->'%(FullPath)')" TargetFramework="$(TargetFramework)" />
<ReferenceAssembliesOutput Include="@(DocumentationProjectOutputGroupOutput->'%(FullPath)')" TargetFramework="$(TargetFramework)" />
</ItemGroup>
</Target>

<!-- If we have any ReferenceAssemblyProjectReference items, ensure restore is called on them -->
<Target Name="_ExtrasRestoreReferenceAssembly" AfterTargets="_LoadRestoreGraphEntryPoints" BeforeTargets="_FilterRestoreGraphProjectInputItems">
<PropertyGroup>
<_ExtrasHasReferenceAssembly Condition="'@(ReferenceAssemblyProjectReference)' != ''">true</_ExtrasHasReferenceAssembly>
<_ExtrasHasReferenceAssembly Condition="'$(_ExtrasHasReferenceAssembly)' == ''">false</_ExtrasHasReferenceAssembly>
</PropertyGroup>


<ItemGroup Condition="'$(_ExtrasHasReferenceAssembly)' == 'true' ">
<RestoreGraphProjectInputItems Include="@(ReferenceAssemblyProjectReference->'%(FullPath)')" />
</ItemGroup>
</Target>

<!-- Pass clean to reference assm -->
<Target Name="_ExtrasCoreClean" BeforeTargets="CoreClean">
<PropertyGroup>
<_ExtrasHasReferenceAssembly Condition="'@(ReferenceAssemblyProjectReference)' != ''">true</_ExtrasHasReferenceAssembly>
<_ExtrasHasReferenceAssembly Condition="'$(_ExtrasHasReferenceAssembly)' == ''">false</_ExtrasHasReferenceAssembly>
</PropertyGroup>

<MSBuild Projects="@(ReferenceAssemblyProjectReference->'%(FullPath)')"
Condition="'$(_ExtrasHasReferenceAssembly)' == 'true'"
BuildInParallel="$(BuildInParallel)"
ContinueOnError="!$(BuildingProject)"
Targets="Clean"
Properties="AssemblyName=$(AssemblyName);Version=$(Version);AssemblyTitle=$(AssemblyTitle);ExtrasIsReferenceAssembly=true"
RemoveProperties="TargetFramework;RuntimeIdentifier"

/>
</Target>

<!-- Pass Build to reference assm -->
<!-- Note: this will build once per inner build. Up-to-date checks should prevent issues -->
<Target Name="_ExtrasCoreBuild" BeforeTargets="CoreBuild" DependsOnTargets="GetAssemblyAttributes">
<PropertyGroup>
<_ExtrasHasReferenceAssembly Condition="'@(ReferenceAssemblyProjectReference)' != ''">true</_ExtrasHasReferenceAssembly>
<_ExtrasHasReferenceAssembly Condition="'$(_ExtrasHasReferenceAssembly)' == ''">false</_ExtrasHasReferenceAssembly>
</PropertyGroup>

<ItemGroup Condition="'$(AssemblyOriginatorKeyFile)' != '' ">
<_SdkAssemblyKeyFile Include="$(AssemblyOriginatorKeyFile)" />
<_SdkAssemblyKeyFileFull Include="@(_SdkAssemblyKeyFile->'%(FullPath)')"/>
</ItemGroup>

<PropertyGroup Condition="'$(AssemblyOriginatorKeyFile)' != '' ">
<_SdkAssemblyKeyFileFullProp>@(_SdkAssemblyKeyFileFull)</_SdkAssemblyKeyFileFullProp>
</PropertyGroup>
<MSBuild Projects="@(ReferenceAssemblyProjectReference->'%(FullPath)')"
Condition="'$(_ExtrasHasReferenceAssembly)' == 'true'"
BuildInParallel="$(BuildInParallel)"
ContinueOnError="!$(BuildingProject)"
Targets="Build"
Properties="AssemblyName=$(AssemblyName);NeutralLanguage=$(NeutralLanguage);AssemblyVersion=$(AssemblyVersion);FileVersion=$(FileVersion);InformationalVersion=$(InformationalVersion);DelaySign=$(DelaySign);SignAssembly=$(SignAssembly);AssemblyOriginatorKeyFile=$(_SdkAssemblyKeyFileFullProp);GenerateDocumentationFile=$(GenerateDocumentationFile);ExtrasIsReferenceAssembly=true"
RemoveProperties="TargetFramework;RuntimeIdentifier"

/>
</Target>

<!-- Pack Refs correctly -->
<Target Name="_ExtrasGetRefsForPackage"
BeforeTargets="_GetPackageFiles">

<PropertyGroup>
<_ExtrasHasReferenceAssembly Condition="'@(ReferenceAssemblyProjectReference)' != ''">true</_ExtrasHasReferenceAssembly>
<_ExtrasHasReferenceAssembly Condition="'$(_ExtrasHasReferenceAssembly)' == ''">false</_ExtrasHasReferenceAssembly>
</PropertyGroup>

<ItemGroup Condition="'$(AssemblyOriginatorKeyFile)' != '' ">
<_SdkAssemblyKeyFile Include="$(AssemblyOriginatorKeyFile)" />
<_SdkAssemblyKeyFileFull Include="@(_SdkAssemblyKeyFile->'%(FullPath)')"/>
</ItemGroup>

<PropertyGroup Condition="'$(AssemblyOriginatorKeyFile)' != '' ">
<_SdkAssemblyKeyFileFullProp>@(_SdkAssemblyKeyFileFull)</_SdkAssemblyKeyFileFullProp>
</PropertyGroup>

<MSBuild Projects="@(ReferenceAssemblyProjectReference->'%(FullPath)')"
Properties="ExtrasIsReferenceAssembly=true"
Condition="'$(_ExtrasHasReferenceAssembly)' == 'true'"
Targets="_GetTargetFrameworksOutput">

<Output TaskParameter="TargetOutputs"
ItemName="_RefTargetFrameworks" />
</MSBuild>

<MSBuild Projects="@(ReferenceAssemblyProjectReference->'%(FullPath)')"
Condition="'$(_ExtrasHasReferenceAssembly)' == 'true'"
Targets="_SdkGetReferenceAssemblies"
Properties="TargetFramework=%(_RefTargetFrameworks.Identity);AssemblyName=$(AssemblyName);NeutralLanguage=$(NeutralLanguage);AssemblyVersion=$(AssemblyVersion);FileVersion=$(FileVersion);InformationalVersion=$(InformationalVersion);DelaySign=$(DelaySign);SignAssembly=$(SignAssembly);AssemblyOriginatorKeyFile=$(_SdkAssemblyKeyFileFullProp);GenerateDocumentationFile=$(GenerateDocumentationFile);ExtrasIsReferenceAssembly=true"
>

<Output TaskParameter="TargetOutputs"
ItemName="_ExtrasRefAssmOutputs" />
</MSBuild>

<ItemGroup>
<None Include="@(_ExtrasRefAssmOutputs)" PackagePath="ref/%(_ExtrasRefAssmOutputs.TargetFramework)" Pack="true" />
</ItemGroup>

</Target>


</Project>
19 changes: 19 additions & 0 deletions Tests/Classlibrary.Ref/Classlibrary.Ref.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="$(MSBuildThisFileDirectory)..\..\Source\MSBuild.Sdk.Extras\BuildMultiTargeting\MSBuild.Sdk.Extras.props" />

<PropertyGroup>
<!--<TargetFramework>uap10.0</TargetFramework>-->
<TargetFrameworks>netstandard1.4;netstandard2.0</TargetFrameworks>
</PropertyGroup>


<ItemGroup>
<Compile Include="..\ClassLibrary\**\*.cs" Exclude="..\ClassLibrary\obj\**" />
</ItemGroup>

<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
<Import Project="$(MSBuildThisFileDirectory)..\..\Source\MSBuild.Sdk.Extras\BuildMultiTargeting\MSBuild.Sdk.Extras.targets" />
<Import Project="..\Test.targets" />

</Project>
3 changes: 2 additions & 1 deletion Tests/Classlibrary/Class.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;

namespace MSBuild.NET.Sdk.Tests
namespace MSBuild.Sdk.Extras.Tests
{
public class Class
{
int SomeMethod(int a, int b) => a + b;
}
}
12 changes: 9 additions & 3 deletions Tests/Classlibrary/Classlibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
<!--<TargetFramework>uap10.0</TargetFramework>-->
<!--<TargetFrameworks>uap10.0;uap10.0.16299;monoandroid70;xamarin.ios10;xamarin.mac20</TargetFrameworks>-->
<TargetFrameworks>uap10.0;monoandroid70;xamarin.ios10;xamarin.mac20;net462</TargetFrameworks>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>test.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<ReferenceAssemblyProjectReference Include="..\Classlibrary.Ref\Classlibrary.Ref.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'uap10.0'">
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="5.4.0" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="5.4.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'uap10.0.16299'">
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="5.4.0" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="5.4.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'tizen30'">
Expand Down
Binary file added Tests/Classlibrary/test.snk
Binary file not shown.
19 changes: 19 additions & 0 deletions Tests/ClasslibraryAsSdk.Ref/ClasslibraryAsSdk.Ref.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project>

<Import Project="$(MSBuildThisFileDirectory)..\..\Source\MSBuild.Sdk.Extras\Sdk\Sdk.props" />

<PropertyGroup>
<!--<TargetFramework>uap10.0</TargetFramework>-->
<TargetFrameworks>netstandard1.4;netstandard2.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<ExtrasIsReferenceAssembly>true</ExtrasIsReferenceAssembly>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\ClassLibraryAsSdk\**\*.cs" Exclude="..\ClassLibraryAsSdk\obj\**" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\Source\MSBuild.Sdk.Extras\Sdk\Sdk.targets" />
<Import Project="..\Test.targets" />

</Project>
5 changes: 3 additions & 2 deletions Tests/ClasslibraryAsSdk/Class.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;

namespace MSBuild.NET.Sdk.Tests
namespace MSBuild.Sdk.Extras.Tests
{
public class Class
{
}
int SomeMethod(int a, int b) => a + b;
}
}
2 changes: 1 addition & 1 deletion Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

<Import Project="$(MSBuildThisFileDirectory)..\..\Source\MSBuild.Sdk.Extras\Sdk\Sdk.targets" />
<Import Project="..\Test.targets" />

</Project>

0 comments on commit 321123e

Please sign in to comment.