forked from dotnet/msbuild
/
ToolsetConfigurationNet5_Tests.cs
79 lines (68 loc) · 3.68 KB
/
ToolsetConfigurationNet5_Tests.cs
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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if !FEATURE_SYSTEM_CONFIGURATION
/* This test is designed especially to test Configuration parsing in net5.0
* which means it WON'T work in net472 and thus we don't run it in net472 */
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Xunit;
using System.Collections.Generic;
namespace Microsoft.Build.UnitTests.Evaluation
{
/// <summary>
/// Unit tests for MSBuild Net5.0 Configuration Parsing
/// </summary>
public class ToolsetConfigurationNet5Test
{
[Fact]
// The default ToolsetDefintionLocations is None, which results in only the local which results in only the several included
// paths such as SDK path and RoslynTargetPath and nothing else. This behavior is expected and the exact same as before.
public void ToolsetDefinitionLocationsIsDefault()
{
var projectCollection = new ProjectCollection();
IDictionary<string, string> toolsetProperties
= new Dictionary<string, string>();
foreach (Toolset toolset in projectCollection.Toolsets)
{
foreach (KeyValuePair<string, ProjectPropertyInstance> properties in toolset.Properties)
{
toolsetProperties[properties.Value.Name] = properties.Value.EvaluatedValue;
}
}
Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath"));
Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath"));
Assert.NotEqual(string.Empty, toolsetProperties["MSBuildSDKsPath"]);
Assert.NotEqual(string.Empty, toolsetProperties["RoslynTargetsPath"]);
Assert.False(toolsetProperties.ContainsKey("VCTargetsPath"));
Assert.False(toolsetProperties.ContainsKey("MSBuildToolsRoot"));
Assert.False(toolsetProperties.ContainsKey("MSBuildExtensionsPath"));
}
[Fact]
// With ToolsetDefintionLocations set to ConfigurationFile (Which would only happen in net5.0 if the user decides to set it).
// Most toolsets are available and the MsBuildTools and SDK paths are all in the net5.0 runtime.
public void ToolsetDefinitionLocationsIsConfiguration()
{
var projectCollection = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile);
IDictionary<string, string> toolsetProperties
= new Dictionary<string, string>();
foreach (Toolset toolset in projectCollection.Toolsets)
{
foreach (KeyValuePair<string, ProjectPropertyInstance> properties in toolset.Properties)
{
toolsetProperties[properties.Value.Name] = properties.Value.EvaluatedValue;
}
}
Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath"));
Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath"));
Assert.NotEqual(string.Empty, toolsetProperties["MSBuildSDKsPath"]);
Assert.NotEqual(string.Empty, toolsetProperties["RoslynTargetsPath"]);
Assert.True(toolsetProperties.ContainsKey("VCTargetsPath"));
Assert.True(toolsetProperties.ContainsKey("MSBuildToolsRoot"));
Assert.True(toolsetProperties.ContainsKey("MSBuildExtensionsPath"));
Assert.NotEqual(string.Empty, toolsetProperties["VCTargetsPath"]);
Assert.NotEqual(string.Empty, toolsetProperties["MSBuildToolsRoot"]);
Assert.NotEqual(string.Empty, toolsetProperties["MSBuildExtensionsPath"]);
}
}
}
#endif