forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs
More file actions
96 lines (76 loc) · 3.48 KB
/
GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs
File metadata and controls
96 lines (76 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.DotNet.Cli.Build.Tests
{
public class GivenThatWeWantToBeBackwardsCompatibleWith1xProjects : SdkTest
{
public GivenThatWeWantToBeBackwardsCompatibleWith1xProjects(ITestOutputHelper log) : base(log)
{
}
[RequiresSpecificFrameworkTheory("netcoreapp1.1")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
public void ItRestoresBuildsAndRuns(string target)
{
var testAppName = "TestAppSimple";
var testInstance = _testAssetsManager.CopyTestAsset(testAppName, identifier: target.Replace('.', '_'))
.WithSource();
// Replace the 'TargetFramework'
ChangeProjectTargetFramework(Path.Combine(testInstance.Path, $"{testAppName}.csproj"), target);
var buildCommand = new BuildCommand(testInstance);
buildCommand
.Execute()
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
var outputDll = Path.Combine(buildCommand.GetOutputDirectory(target, configuration).FullName, $"{testAppName}.dll");
new DotnetCommand(Log)
.Execute(outputDll)
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
}
[Theory]
[InlineData("netstandard1.3")]
[InlineData("netstandard1.6")]
public void ItRestoresBuildsAndPacks(string target)
{
var testAppName = "TestAppSimple";
var testInstance = _testAssetsManager.CopyTestAsset(testAppName, identifier: target.Replace('.', '_'))
.WithSource();
// Replace the 'TargetFramework'
ChangeProjectTargetFramework(Path.Combine(testInstance.Path, $"{testAppName}.csproj"), target);
new BuildCommand(testInstance)
.Execute()
.Should().Pass();
new PackCommand(Log, testInstance.Path)
.Execute()
.Should().Pass();
}
[RequiresSpecificFrameworkFact("netcoreapp1.0")] // https://github.com/dotnet/cli/issues/6087
public void ItRunsABackwardsVersionedTool()
{
var testInstance = _testAssetsManager
.CopyTestAsset("11TestAppWith10CLIToolReferences")
.WithSource();
NuGetConfigWriter.Write(testInstance.Path, TestContext.Current.TestPackages);
new RestoreCommand(testInstance)
.Execute()
.Should()
.Pass();
new DotnetCommand(Log)
.WithWorkingDirectory(testInstance.Path)
.Execute("outputsframeworkversion-netcoreapp1.0")
.Should()
.Pass()
.And
.HaveStdOutContaining("netcoreapp1.0");
}
void ChangeProjectTargetFramework(string projectFile, string target)
{
var projectXml = XDocument.Load(projectFile);
var ns = projectXml.Root?.Name.Namespace ?? string.Empty;
var propertyGroup = projectXml.Root?.Elements(ns + "PropertyGroup").First();
var rootNamespaceElement = propertyGroup?.Element(ns + "TargetFramework");
rootNamespaceElement?.SetValue(target);
projectXml.Save(projectFile.ToString());
}
}
}