Skip to content

Commit a7ea14c

Browse files
author
Piotr Puszkiewicz
authored
Merge pull request #828 from piotrpMSFT/piotrpMSFT/issues/696/p2pbuild-r
Enable P2P's to determine their own compilation RID
2 parents b1b92da + 7f5553c commit a7ea14c

19 files changed

+290
-3
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,7 @@ project.json.template
181181

182182
# Ignore Generated project template files
183183
Project.csproj
184-
Project.vbproj
184+
Project.vbproj
185+
186+
# VS Code
187+
.vscode/

DotnetCLIVersion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0-rc4-004771
1+
1.0.0-rc4-004828
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp1.0</TargetFramework>
6+
<RuntimeIdentifiers>osx.10.11-x64;ubuntu.14.04-x64;win10-x64</RuntimeIdentifiers>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\LibraryWithRid\LibraryWithRid.csproj" />
11+
<ProjectReference Include="..\LibraryWithRids\LibraryWithRids.csproj" />
12+
<ProjectReference Include="..\LibraryWithoutRid\LibraryWithoutRid.csproj" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace App
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
var libraryWithRidNativeOutput = LibraryWithRid.NativeCode.InvokeNativeCodeAndReturnAString();
10+
11+
var libraryWithRidsNativeOutput = LibraryWithRid.NativeCode.InvokeNativeCodeAndReturnAString();
12+
13+
var libraryWithRidCompileTimeRid = LibraryWithRid.NativeCode.GetRidStoredInAssemblyDescriptionAttribute();
14+
15+
var libraryWithRidsCompileTimeRid = LibraryWithRids.NativeCode.GetRidStoredInAssemblyDescriptionAttribute();
16+
17+
var libraryWithRidStatus = $"{libraryWithRidNativeOutput} {libraryWithRidCompileTimeRid}";
18+
19+
var libraryWithRidsStatus = $"{libraryWithRidsNativeOutput} {libraryWithRidsCompileTimeRid}";
20+
21+
var portableLibraryStatus = LibraryWithoutRid.PortableClass.GetHelloWorld();
22+
23+
Console.WriteLine($"{libraryWithRidStatus} {libraryWithRidsStatus} {portableLibraryStatus}");
24+
}
25+
}
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard1.4</TargetFramework>
4+
<RuntimeIdentifier>$(TestRuntimeIdentifier)</RuntimeIdentifier>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<Description>'$(RuntimeIdentifier)'</Description>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<PackageReference Include="SQLite">
11+
<Version>3.13.0</Version>
12+
</PackageReference>
13+
</ItemGroup>
14+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibraryWithRid
5+
{
6+
public static class LinuxNativeMethods
7+
{
8+
[DllImport("libsqlite3", CallingConvention = CallingConvention.Cdecl)]
9+
public static extern IntPtr sqlite3_libversion();
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibraryWithRid
5+
{
6+
public static class MacNativeMethods
7+
{
8+
[DllImport("libsqlite3", CallingConvention = CallingConvention.Cdecl)]
9+
public static extern IntPtr sqlite3_libversion();
10+
}
11+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Runtime.InteropServices;
4+
5+
namespace LibraryWithRid
6+
{
7+
public class NativeCode
8+
{
9+
public static string InvokeNativeCodeAndReturnAString()
10+
{
11+
switch(GetRidStoredInAssemblyDescriptionAttribute())
12+
{
13+
case "'ubuntu.14.04-x64'":
14+
return Marshal.PtrToStringAnsi(LinuxNativeMethods.sqlite3_libversion());
15+
case "'osx.10.11-x64'":
16+
return Marshal.PtrToStringAnsi(MacNativeMethods.sqlite3_libversion());
17+
case "'win10-x64'":
18+
return Marshal.PtrToStringAnsi(WindowsNativeMethods.sqlite3_libversion());
19+
default:
20+
return "Unexpected RID. Cannot find sqlite3.";
21+
}
22+
}
23+
24+
public static string GetRidStoredInAssemblyDescriptionAttribute()
25+
{
26+
return typeof(NativeCode)
27+
.GetTypeInfo()
28+
.Assembly
29+
.GetCustomAttribute<AssemblyDescriptionAttribute>()
30+
?.Description;
31+
}
32+
}
33+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibraryWithRid
5+
{
6+
public static class WindowsNativeMethods
7+
{
8+
[DllImport("sqlite3", CallingConvention = CallingConvention.Cdecl)]
9+
public static extern IntPtr sqlite3_libversion();
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard1.4</TargetFramework>
4+
<RuntimeIdentifiers>osx.10.11-x64;ubuntu.14.04-x64;win10-x64</RuntimeIdentifiers>
5+
<Description>'$(RuntimeIdentifier)'</Description>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="SQLite">
9+
<Version>3.13.0</Version>
10+
</PackageReference>
11+
</ItemGroup>
12+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibraryWithRids
5+
{
6+
public static class LinuxNativeMethods
7+
{
8+
[DllImport("libsqlite3", CallingConvention = CallingConvention.Cdecl)]
9+
public static extern IntPtr sqlite3_libversion();
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibraryWithRids
5+
{
6+
public static class MacNativeMethods
7+
{
8+
[DllImport("libsqlite3", CallingConvention = CallingConvention.Cdecl)]
9+
public static extern IntPtr sqlite3_libversion();
10+
}
11+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Runtime.InteropServices;
4+
5+
namespace LibraryWithRids
6+
{
7+
public class NativeCode
8+
{
9+
public static string InvokeNativeCodeAndReturnAString()
10+
{
11+
switch(GetRidStoredInAssemblyDescriptionAttribute())
12+
{
13+
case "'ubuntu.14.04-x64'":
14+
return Marshal.PtrToStringAnsi(LinuxNativeMethods.sqlite3_libversion());
15+
case "'osx.10.11-x64'":
16+
return Marshal.PtrToStringAnsi(MacNativeMethods.sqlite3_libversion());
17+
case "'win10-x64'":
18+
return Marshal.PtrToStringAnsi(WindowsNativeMethods.sqlite3_libversion());
19+
default:
20+
return "Unexpected RID. Cannot find sqlite3.";
21+
}
22+
}
23+
24+
public static string GetRidStoredInAssemblyDescriptionAttribute()
25+
{
26+
return typeof(NativeCode)
27+
.GetTypeInfo()
28+
.Assembly
29+
.GetCustomAttribute<AssemblyDescriptionAttribute>()
30+
?.Description;
31+
}
32+
}
33+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibraryWithRids
5+
{
6+
public static class WindowsNativeMethods
7+
{
8+
[DllImport("sqlite3", CallingConvention = CallingConvention.Cdecl)]
9+
public static extern IntPtr sqlite3_libversion();
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard1.4</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace LibraryWithoutRid
4+
{
5+
public class PortableClass
6+
{
7+
public static string GetHelloWorld()
8+
{
9+
return "Hello World";
10+
}
11+
}
12+
}

build/build.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
DestinationFolder="$(TestsDirectory)"
165165
/>
166166

167+
<Message Text="$(DotNetTool) &quot;$(TestsDirectory)\xunit.console.netcore.exe&quot; &quot;@(TestAssembly, '&quot; &quot;')&quot; -xml &quot;@(XmlTestFile)&quot;" Importance="High" />
167168
<Exec Command="$(DotNetTool) &quot;$(TestsDirectory)\xunit.console.netcore.exe&quot; &quot;@(TestAssembly, '&quot; &quot;')&quot; -xml &quot;@(XmlTestFile)&quot;"
168169
LogStandardErrorAsError="true"
169170
WorkingDirectory="$(TestsDirectory)"

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.Common.targets

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ Copyright (c) .NET Foundation. All rights reserved.
5151
with the referencing project's target framework.
5252
============================================================
5353
-->
54-
<Target Name="GetTargetFrameworkProperties" Returns="TargetFramework=$(NearestTargetFramework);ProjectHasSingleTargetFramework=$(_HasSingleTargetFramework)">
54+
<Target Name="GetTargetFrameworkProperties" Returns="TargetFramework=$(NearestTargetFramework);ProjectHasSingleTargetFramework=$(_HasSingleTargetFramework);ProjectIsRidAgnostic=$(_IsRidAgnostic)">
5555

5656
<PropertyGroup>
57+
<!-- indicate to caller that project is RID agnostic so that a global property RuntimeIdentifier value can be removed -->
58+
<_IsRidAgnostic>false</_IsRidAgnostic>
59+
<_IsRidAgnostic Condition=" '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' ">true</_IsRidAgnostic>
60+
5761
<!-- If a ReferringTargetFramework was not specified, and we only have one TargetFramework, then don't try to check compatibility -->
5862
<_SkipNearestTargetFrameworkResolution Condition="'$(TargetFramework)' != '' and '$(ReferringTargetFramework)' == ''">true</_SkipNearestTargetFrameworkResolution>
5963
<NearestTargetFramework Condition="'$(_SkipNearestTargetFrameworkResolution)' == 'true'">$(TargetFramework)</NearestTargetFramework>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using FluentAssertions;
5+
using Microsoft.DotNet.Cli.Utils;
6+
using Microsoft.DotNet.InternalAbstractions;
7+
using Microsoft.NET.TestFramework;
8+
using Microsoft.NET.TestFramework.Commands;
9+
using Microsoft.NET.TestFramework.Assertions;
10+
using System.IO;
11+
using Xunit;
12+
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;
13+
14+
namespace Microsoft.NET.Build.Tests
15+
{
16+
public class GivenThatWeWantToBuildASelfContainedAppWithLibrariesAndRid : SdkTest
17+
{
18+
[Fact]
19+
public void It_builds_a_RID_specific_runnable_output()
20+
{
21+
if (UsingFullFrameworkMSBuild)
22+
{
23+
// Disable this test on full framework, as the current build won't have access to
24+
// https://github.com/Microsoft/msbuild/pull/1674
25+
// See https://github.com/dotnet/sdk/issues/877
26+
return;
27+
}
28+
29+
var runtimeIdentifier = RuntimeEnvironment.GetRuntimeIdentifier();
30+
var testAsset = _testAssetsManager
31+
.CopyTestAsset("AppWithLibraryAndRid")
32+
.WithSource();
33+
34+
var projectPath = Path.Combine(testAsset.TestRoot, "App");
35+
36+
var restoreCommand = new RestoreCommand(Stage0MSBuild, projectPath, "App.csproj");
37+
restoreCommand
38+
.Execute($"/p:TestRuntimeIdentifier={runtimeIdentifier}")
39+
.Should()
40+
.Pass();
41+
42+
var buildCommand = new BuildCommand(Stage0MSBuild, projectPath);
43+
44+
buildCommand
45+
.Execute($"/p:RuntimeIdentifier={runtimeIdentifier}", $"/p:TestRuntimeIdentifier={runtimeIdentifier}")
46+
.Should()
47+
.Pass();
48+
49+
var outputDirectory = buildCommand.GetOutputDirectory("netcoreapp1.0");
50+
var selfContainedExecutable = $"App{Constants.ExeSuffix}";
51+
52+
Command.Create(Path.Combine(outputDirectory.FullName, selfContainedExecutable), new string[] { })
53+
.CaptureStdOut()
54+
.Execute()
55+
.Should()
56+
.Pass()
57+
.And
58+
.HaveStdOutContaining($"3.13.0 '{runtimeIdentifier}' 3.13.0 '{runtimeIdentifier}' Hello World");
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)