Fix desktop standalone scenario

This commit is contained in:
Pavel Krymets 2016-04-25 14:31:52 -07:00
parent b5046edcb9
commit f3b47cabf1
6 changed files with 65 additions and 12 deletions

View file

@ -0,0 +1,11 @@
using System;
namespace DesktopAppWithRuntimes
{
public static class Program
{
public static void Main(string[] args)
{
}
}
}

View file

@ -0,0 +1,16 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.Windows.ApiSets": "1.0.1-rc2-*"
},
"compilationOptions": {
"emitEntryPoint": true
},
"frameworks": {
"net451": {}
},
"runtimes":
{
"win7-x64": {}
}
}

View file

@ -239,7 +239,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
compilerOptions: includeCompile ? _compilerOptions : null, compilerOptions: includeCompile ? _compilerOptions : null,
compilationExports: includeCompile ? exports : null, compilationExports: includeCompile ? exports : null,
runtimeExports: exports, runtimeExports: exports,
portable: string.IsNullOrEmpty(_context.RuntimeIdentifier), portable: _context.IsPortable,
target: _context.TargetFramework, target: _context.TargetFramework,
runtime: _context.RuntimeIdentifier ?? string.Empty); runtime: _context.RuntimeIdentifier ?? string.Empty);

View file

@ -241,7 +241,7 @@ namespace Microsoft.DotNet.ProjectModel
.Cast<LibraryRange?>() .Cast<LibraryRange?>()
.FirstOrDefault(); .FirstOrDefault();
} }
bool isPortable = platformDependency != null || TargetFramework.IsDesktop(); bool isPortable = platformDependency != null;
LockFileTarget target = null; LockFileTarget target = null;
LibraryDescription platformLibrary = null; LibraryDescription platformLibrary = null;
@ -262,9 +262,11 @@ namespace Microsoft.DotNet.ProjectModel
} }
} }
string runtime; string runtime = target?.RuntimeIdentifier;
if (TargetFramework.IsDesktop()) if (string.IsNullOrEmpty(runtime) && TargetFramework.IsDesktop())
{ {
// we got a ridless target for desktop so turning portable mode on
isPortable = true;
var legacyRuntime = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); var legacyRuntime = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
if (RuntimeIdentifiers.Contains(legacyRuntime)) if (RuntimeIdentifiers.Contains(legacyRuntime))
{ {
@ -275,10 +277,6 @@ namespace Microsoft.DotNet.ProjectModel
runtime = RuntimeIdentifiers.FirstOrDefault(); runtime = RuntimeIdentifiers.FirstOrDefault();
} }
} }
else
{
runtime = target?.RuntimeIdentifier;
}
var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(frameworkReferenceResolver); var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(frameworkReferenceResolver);
bool requiresFrameworkAssemblies; bool requiresFrameworkAssemblies;

View file

@ -15,6 +15,13 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{ {
public class PublishDesktopTests : TestBase public class PublishDesktopTests : TestBase
{ {
private TestAssetsManager _testAssetsManager;
public PublishDesktopTests()
{
_testAssetsManager = GetTestGroupTestAssetsManager("DesktopTestProjects");
}
[WindowsOnlyTheory] [WindowsOnlyTheory]
[InlineData(null, null)] [InlineData(null, null)]
[InlineData("win7-x64", "the-win-x64-version.txt")] [InlineData("win7-x64", "the-win-x64-version.txt")]
@ -26,7 +33,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
expectedOutputName = $"the-win-{RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()}-version.txt"; expectedOutputName = $"the-win-{RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()}-version.txt";
} }
var testInstance = TestAssetsManager.CreateTestInstance(Path.Combine("..", "DesktopTestProjects", "DesktopAppWithNativeDep")) var testInstance = _testAssetsManager.CreateTestInstance("DesktopAppWithNativeDep")
.WithLockFiles(); .WithLockFiles();
var publishCommand = new PublishCommand(testInstance.TestRoot, runtime: runtime); var publishCommand = new PublishCommand(testInstance.TestRoot, runtime: runtime);
@ -55,7 +62,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
var testInstance = GetTestInstance() var testInstance = GetTestInstance()
.WithLockFiles(); .WithLockFiles();
var publishCommand = new PublishCommand(Path.Combine(testInstance.TestRoot, project), runtime: runtime); // Prevent path too long failure on CI machines
var projectPath = Path.Combine(testInstance.TestRoot, project);
var publishCommand = new PublishCommand(projectPath, runtime: runtime, output: Path.Combine(projectPath, "out"));
var result = await publishCommand.ExecuteAsync(); var result = await publishCommand.ExecuteAsync();
result.Should().Pass(); result.Should().Pass();
@ -123,9 +132,28 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
} }
} }
private static TestInstance GetTestInstance([CallerMemberName] string callingMethod = "")
[WindowsOnlyFact]
public async Task DesktopApp_WithRuntimes_PublishedSplitPackageAssets()
{ {
return TestAssetsManager.CreateTestInstance(Path.Combine("..", "DesktopTestProjects", "DesktopKestrelSample"), callingMethod); var testInstance = _testAssetsManager.CreateTestInstance("DesktopAppWithRuntimes")
.WithLockFiles();
var publishCommand = new PublishCommand(testInstance.TestRoot, runtime: "win7-x64");
var result = await publishCommand.ExecuteAsync();
result.Should().Pass();
// Test the output
var outputDir = publishCommand.GetOutputDirectory(portable: false);
System.Console.WriteLine(outputDir);
outputDir.Should().HaveFile("api-ms-win-core-file-l1-1-0.dll");
outputDir.Should().HaveFile(publishCommand.GetOutputExecutable());
}
private TestInstance GetTestInstance([CallerMemberName] string callingMethod = "")
{
return _testAssetsManager.CreateTestInstance("DesktopKestrelSample", callingMethod);
} }
} }
} }