2020-05-06 14:59:23 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
2018-11-20 18:53:39 +00:00
|
|
|
|
using System.IO;
|
2020-10-16 16:39:31 +00:00
|
|
|
|
using System.Linq;
|
2020-04-21 20:54:31 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2018-11-20 18:53:39 +00:00
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace EndToEnd.Tests
|
|
|
|
|
{
|
|
|
|
|
public class ProjectBuildTests : TestBase
|
|
|
|
|
{
|
2020-10-23 20:19:43 +00:00
|
|
|
|
// TODO: Once console template is updated to target net6.0, remove this logic
|
2020-10-27 03:18:09 +00:00
|
|
|
|
// https://github.com/dotnet/installer/issues/8974
|
2020-10-23 20:19:43 +00:00
|
|
|
|
void RetargetProject(string projectDirectory)
|
|
|
|
|
{
|
|
|
|
|
var projectFile = Directory.GetFiles(projectDirectory, "*.csproj").Single();
|
|
|
|
|
|
|
|
|
|
var projectXml = XDocument.Load(projectFile);
|
|
|
|
|
var ns = projectXml.Root.Name.Namespace;
|
|
|
|
|
|
|
|
|
|
projectXml.Root.Element(ns + "PropertyGroup")
|
|
|
|
|
.Element(ns + "TargetFramework").Value = "net6.0";
|
|
|
|
|
|
|
|
|
|
projectXml.Save(projectFile);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 18:53:39 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItCanNewRestoreBuildRunCleanMSBuildProject()
|
|
|
|
|
{
|
|
|
|
|
var directory = TestAssets.CreateTestDirectory();
|
|
|
|
|
string projectDirectory = directory.FullName;
|
|
|
|
|
|
|
|
|
|
string newArgs = "console --debug:ephemeral-hive --no-restore";
|
|
|
|
|
new NewCommandShim()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(newArgs)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
2020-10-23 20:19:43 +00:00
|
|
|
|
RetargetProject(projectDirectory);
|
|
|
|
|
|
2018-11-20 18:53:39 +00:00
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var runCommand = new RunCommand()
|
2019-10-02 19:32:23 +00:00
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.ExecuteWithCapturedOutput()
|
2020-02-25 16:09:40 +00:00
|
|
|
|
.Should().Pass().And.HaveStdOutContaining("Hello World!");
|
2018-11-20 18:53:39 +00:00
|
|
|
|
|
|
|
|
|
var binDirectory = new DirectoryInfo(projectDirectory).Sub("bin");
|
|
|
|
|
binDirectory.Should().HaveFilesMatching("*.dll", SearchOption.AllDirectories);
|
|
|
|
|
|
|
|
|
|
new CleanCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
binDirectory.Should().NotHaveFilesMatching("*.dll", SearchOption.AllDirectories);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 19:32:23 +00:00
|
|
|
|
[Fact]
|
2019-01-07 21:55:18 +00:00
|
|
|
|
public void ItCanRunAnAppUsingTheWebSdk()
|
|
|
|
|
{
|
|
|
|
|
var directory = TestAssets.CreateTestDirectory();
|
|
|
|
|
string projectDirectory = directory.FullName;
|
|
|
|
|
|
|
|
|
|
string newArgs = "console --debug:ephemeral-hive --no-restore";
|
|
|
|
|
new NewCommandShim()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(newArgs)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
2020-10-23 20:19:43 +00:00
|
|
|
|
RetargetProject(projectDirectory);
|
|
|
|
|
|
2019-01-07 21:55:18 +00:00
|
|
|
|
string projectPath = Path.Combine(projectDirectory, directory.Name + ".csproj");
|
|
|
|
|
|
|
|
|
|
var project = XDocument.Load(projectPath);
|
|
|
|
|
var ns = project.Root.Name.Namespace;
|
|
|
|
|
|
|
|
|
|
project.Root.Attribute("Sdk").Value = "Microsoft.NET.Sdk.Web";
|
|
|
|
|
|
|
|
|
|
project.Save(projectPath);
|
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var runCommand = new RunCommand()
|
2019-10-02 19:32:23 +00:00
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.ExecuteWithCapturedOutput()
|
2020-02-25 16:09:40 +00:00
|
|
|
|
.Should().Pass().And.HaveStdOutContaining("Hello World!");
|
2019-01-07 21:55:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 16:39:31 +00:00
|
|
|
|
[WindowsOnlyFact]
|
|
|
|
|
public void ItCanPublishArm64Winforms()
|
|
|
|
|
{
|
|
|
|
|
DirectoryInfo directory = TestAssets.CreateTestDirectory();
|
|
|
|
|
string projectDirectory = directory.FullName;
|
|
|
|
|
|
|
|
|
|
string newArgs = "winforms --no-restore";
|
|
|
|
|
new NewCommandShim()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(newArgs)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
string publishArgs="-r win-arm64";
|
|
|
|
|
new PublishCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(publishArgs)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var selfContainedPublishDir = new DirectoryInfo(projectDirectory)
|
|
|
|
|
.Sub("bin").Sub("Debug").GetDirectories().FirstOrDefault()
|
|
|
|
|
.Sub("win-arm64").Sub("publish");
|
|
|
|
|
|
|
|
|
|
selfContainedPublishDir.Should().HaveFilesMatching("System.Windows.Forms.dll", SearchOption.TopDirectoryOnly);
|
|
|
|
|
selfContainedPublishDir.Should().HaveFilesMatching($"{directory.Name}.dll", SearchOption.TopDirectoryOnly);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[WindowsOnlyFact]
|
|
|
|
|
public void ItCantPublishArm64Wpf()
|
|
|
|
|
{
|
|
|
|
|
DirectoryInfo directory = TestAssets.CreateTestDirectory();
|
|
|
|
|
string projectDirectory = directory.FullName;
|
|
|
|
|
|
|
|
|
|
string newArgs = "wpf --no-restore";
|
|
|
|
|
new NewCommandShim()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(newArgs)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
string publishArgs="-r win-arm64";
|
|
|
|
|
new PublishCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(publishArgs)
|
|
|
|
|
.Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 18:53:39 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("console")]
|
|
|
|
|
[InlineData("classlib")]
|
|
|
|
|
[InlineData("mstest")]
|
|
|
|
|
[InlineData("nunit")]
|
2018-11-21 02:55:46 +00:00
|
|
|
|
[InlineData("web")]
|
2019-05-20 19:40:08 +00:00
|
|
|
|
[InlineData("mvc")]
|
2018-11-20 18:53:39 +00:00
|
|
|
|
public void ItCanBuildTemplates(string templateName)
|
2018-11-21 03:43:45 +00:00
|
|
|
|
{
|
|
|
|
|
TestTemplateBuild(templateName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[WindowsOnlyTheory]
|
2019-12-28 01:42:00 +00:00
|
|
|
|
[InlineData("wpf", Skip = "https://github.com/dotnet/wpf/issues/2363")]
|
|
|
|
|
[InlineData("winforms", Skip = "https://github.com/dotnet/wpf/issues/2363")]
|
2018-11-21 03:43:45 +00:00
|
|
|
|
public void ItCanBuildDesktopTemplates(string templateName)
|
|
|
|
|
{
|
|
|
|
|
TestTemplateBuild(templateName);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 19:32:23 +00:00
|
|
|
|
[WindowsOnlyTheory]
|
2019-12-28 01:42:00 +00:00
|
|
|
|
[InlineData("wpf", Skip = "https://github.com/dotnet/wpf/issues/2363")]
|
2019-10-02 19:32:23 +00:00
|
|
|
|
public void ItCanBuildDesktopTemplatesSelfContained(string templateName)
|
|
|
|
|
{
|
|
|
|
|
TestTemplateBuild(templateName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("web")]
|
|
|
|
|
[InlineData("console")]
|
|
|
|
|
public void ItCanBuildTemplatesSelfContained(string templateName)
|
|
|
|
|
{
|
|
|
|
|
TestTemplateBuild(templateName, selfContained: true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TestTemplateBuild(string templateName, bool selfContained = false)
|
2018-11-20 18:53:39 +00:00
|
|
|
|
{
|
|
|
|
|
var directory = TestAssets.CreateTestDirectory(identifier: templateName);
|
|
|
|
|
string projectDirectory = directory.FullName;
|
|
|
|
|
|
|
|
|
|
string newArgs = $"{templateName} --debug:ephemeral-hive --no-restore";
|
|
|
|
|
new NewCommandShim()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(newArgs)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
2020-04-21 20:54:31 +00:00
|
|
|
|
var buildArgs = selfContained ? "" :$"-r {RuntimeInformation.RuntimeIdentifier}";
|
2019-09-24 20:59:39 +00:00
|
|
|
|
var dotnetRoot = Path.GetDirectoryName(RepoDirectoriesProvider.DotnetUnderTest);
|
2018-11-20 18:53:39 +00:00
|
|
|
|
new BuildCommand()
|
2019-09-24 20:59:39 +00:00
|
|
|
|
.WithEnvironmentVariable("PATH", dotnetRoot) // override PATH since razor rely on PATH to find dotnet
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
2019-10-02 19:32:23 +00:00
|
|
|
|
.Execute(buildArgs)
|
2019-09-24 20:59:39 +00:00
|
|
|
|
.Should().Pass();
|
2018-11-20 18:53:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|