Skip to content

Commit b52b27b

Browse files
committed
Reenable the c++ CLI tests
Add a test for checking the default include windows SDK behavior for c++ cli
1 parent 2608f32 commit b52b27b

File tree

5 files changed

+114
-15
lines changed

5 files changed

+114
-15
lines changed

src/Assets/TestProjects/CppCliLibWithWpfFrameworkReference/Project1.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<Keyword>NetCoreCProj</Keyword>
2525
<RootNamespace>Project1</RootNamespace>
2626
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27-
<TargetFramework>net5.0</TargetFramework>
27+
<TargetFramework>net7.0</TargetFramework>
2828
</PropertyGroup>
2929
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
3030
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

src/Assets/TestProjects/NetCoreCsharpAppReferenceCppCliLib/CSConsoleApp/CSConsoleApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<Platforms>x64</Platforms>
66
<PlatformTarget>x64</PlatformTarget>
77
</PropertyGroup>

src/Assets/TestProjects/NetCoreCsharpAppReferenceCppCliLib/NETCoreCppCliTest/NETCoreCppCliTest.vcxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
</ProjectConfiguration>
1212
</ItemGroup>
1313
<PropertyGroup Label="Globals">
14-
<VCProjectVersion>16.0</VCProjectVersion>
14+
<VCProjectVersion>17.0</VCProjectVersion>
1515
<ProjectGuid>{CF5DA8D7-1FDF-4E8F-AFE6-450BE16E906A}</ProjectGuid>
16-
<TargetFramework>net5.0</TargetFramework>
16+
<TargetFramework>net7.0</TargetFramework>
1717
<Keyword>ManagedCProj</Keyword>
1818
<RootNamespace>NETCoreCppCliTest</RootNamespace>
1919
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
@@ -22,14 +22,14 @@
2222
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
2323
<ConfigurationType>DynamicLibrary</ConfigurationType>
2424
<UseDebugLibraries>true</UseDebugLibraries>
25-
<PlatformToolset>v142</PlatformToolset>
25+
<PlatformToolset>v143</PlatformToolset>
2626
<CLRSupport>NetCore</CLRSupport>
2727
<CharacterSet>Unicode</CharacterSet>
2828
</PropertyGroup>
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
3030
<ConfigurationType>DynamicLibrary</ConfigurationType>
3131
<UseDebugLibraries>false</UseDebugLibraries>
32-
<PlatformToolset>v142</PlatformToolset>
32+
<PlatformToolset>v143</PlatformToolset>
3333
<CLRSupport>NetCore</CLRSupport>
3434
<CharacterSet>Unicode</CharacterSet>
3535
</PropertyGroup>

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildACppCliProject.cs

Lines changed: 107 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System;
5+
using System.Collections.Generic;
46
using System.IO;
57
using System.Linq;
8+
using System.Security.Cryptography;
69
using System.Xml.Linq;
710
using FluentAssertions;
811
using Microsoft.NET.Build.Tasks;
912
using Microsoft.NET.TestFramework;
1013
using Microsoft.NET.TestFramework.Assertions;
1114
using Microsoft.NET.TestFramework.Commands;
15+
using Microsoft.NET.TestFramework.ProjectConstruction;
16+
using Xunit;
1217
using Xunit.Abstractions;
1318

1419
namespace Microsoft.NET.Build.Tests
@@ -19,7 +24,7 @@ public GivenThatWeWantToBuildACppCliProject(ITestOutputHelper log) : base(log)
1924
{
2025
}
2126

22-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/3785")]
27+
[FullMSBuildOnlyFact]
2328
public void It_builds_and_runs()
2429
{
2530
var testAsset = _testAssetsManager
@@ -40,7 +45,7 @@ public void It_builds_and_runs()
4045
var exe = Path.Combine( //find the platform directory
4146
new DirectoryInfo(Path.Combine(testAsset.TestRoot, "CSConsoleApp", "bin")).GetDirectories().Single().FullName,
4247
"Debug",
43-
"net5.0",
48+
ToolsetInfo.CurrentTargetFramework,
4449
"CSConsoleApp.exe");
4550

4651
var runCommand = new RunExeCommand(Log, exe);
@@ -52,7 +57,27 @@ public void It_builds_and_runs()
5257
.HaveStdOutContaining("Hello, World!");
5358
}
5459

55-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/3785")]
60+
[FullMSBuildOnlyFact]
61+
public void It_builds_and_runs_with_package_reference()
62+
{
63+
var targetFramework = ToolsetInfo.CurrentTargetFramework + "-windows";
64+
var testAsset = _testAssetsManager
65+
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
66+
.WithSource()
67+
.WithProjectChanges((projectPath, project) => ConfigureProject(projectPath, project, "NewtonSoft.Json","13.0.1", targetFramework, new string[] { "_EnablePackageReferencesInVCProjects" , "IncludeWindowsSDKRefFrameworkReferences" }));
68+
69+
// build projects separately with BuildProjectReferences=false to simulate VS build behavior
70+
new BuildCommand(testAsset, "NETCoreCppCliTest")
71+
.Execute("-p:Platform=x64", "-p:EnableManagedpackageReferenceSupport=true", "/bl")
72+
.Should()
73+
.Pass();
74+
75+
var cppnProjProperties = GetPropertyValues(testAsset.TestRoot, "NETCoreCppCliTest", targetFramework: targetFramework);
76+
Assert.True(cppnProjProperties["_EnablePackageReferencesInVCProjects"] == "true");
77+
Assert.True(cppnProjProperties["IncludeWindowsSDKRefFrameworkReferences"] == "");
78+
}
79+
80+
[FullMSBuildOnlyFact]
5681
public void Given_no_restore_It_builds_cpp_project()
5782
{
5883
var testAsset = _testAssetsManager
@@ -65,7 +90,7 @@ public void Given_no_restore_It_builds_cpp_project()
6590
.Pass();
6691
}
6792

68-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/3785")]
93+
[FullMSBuildOnlyFact]
6994
public void Given_Wpf_framework_reference_It_builds_cpp_project()
7095
{
7196
var testAsset = _testAssetsManager
@@ -78,7 +103,7 @@ public void Given_Wpf_framework_reference_It_builds_cpp_project()
78103
.Pass();
79104
}
80105

81-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/11008")]
106+
[FullMSBuildOnlyFact]
82107
public void It_fails_with_error_message_on_EnableComHosting()
83108
{
84109
var testAsset = _testAssetsManager
@@ -106,7 +131,7 @@ public void It_fails_with_error_message_on_EnableComHosting()
106131
.HaveStdOutContaining(Strings.NoSupportCppEnableComHosting);
107132
}
108133

109-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/11008")]
134+
[FullMSBuildOnlyFact]
110135
public void It_fails_with_error_message_on_fullframework()
111136
{
112137
var testAsset = _testAssetsManager
@@ -123,7 +148,7 @@ public void It_fails_with_error_message_on_fullframework()
123148
.HaveStdOutContaining(Strings.NETFrameworkWithoutUsingNETSdkDefaults);
124149
}
125150

126-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/11008")]
151+
[FullMSBuildOnlyFact]
127152
public void It_fails_with_error_message_on_tfm_lower_than_3_1()
128153
{
129154
var testAsset = _testAssetsManager
@@ -140,7 +165,7 @@ public void It_fails_with_error_message_on_tfm_lower_than_3_1()
140165
.HaveStdOutContaining(Strings.CppRequiresTFMVersion31);
141166
}
142167

143-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/11008")]
168+
[FullMSBuildOnlyFact]
144169
public void When_run_with_selfcontained_It_fails_with_error_message()
145170
{
146171
var testAsset = _testAssetsManager
@@ -166,5 +191,79 @@ private void ChangeTargetFramework(string projectPath, XDocument project, string
166191
.Single().Value = targetFramework;
167192
}
168193
}
194+
195+
private void ConfigureProject(string projectPath, XDocument project, string package, string version, string targetFramework, string[] properties)
196+
{
197+
ChangeTargetFramework(projectPath, project, targetFramework);
198+
AddPackageReference(projectPath, project, package, version);
199+
RecordProperties(projectPath, project, properties);
200+
}
201+
202+
private void AddPackageReference(string projectPath, XDocument project, string package, string version)
203+
{
204+
if (Path.GetExtension(projectPath) == ".vcxproj")
205+
{
206+
XNamespace ns = project.Root.Name.Namespace;
207+
XElement itemGroup = project.Root.Descendants(ns + "ItemGroup").First();
208+
itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", package),
209+
new XAttribute("Version", version)));
210+
211+
}
212+
}
213+
private void RecordProperties(string projectPath, XDocument project, string[] properties)
214+
{
215+
if (Path.GetExtension(projectPath) == ".vcxproj")
216+
{
217+
List<XElement> propertiesElements = new List<XElement>();
218+
XNamespace ns = project.Root.Name.Namespace;
219+
foreach (var propertyName in properties)
220+
{
221+
propertiesElements.Add( new XElement(ns + "LinesToWrite", new XAttribute("Include", @$"{ propertyName }: $({ propertyName })")));
222+
}
223+
224+
// string target = $@"<Target Name='WritePropertyValues' BeforeTargets='AfterBuild'>
225+
// <ItemGroup>
226+
//{propertiesElements}
227+
// </ItemGroup>
228+
// <WriteLinesToFile
229+
// File='$(BaseIntermediateOutputPath)\$(Configuration)\$(TargetFramework)\PropertyValues.txt'
230+
// Lines='@(LinesToWrite)'
231+
// Overwrite='true'
232+
// Encoding='Unicode'
233+
// />
234+
// </Target>";
235+
XElement newNode = new XElement(ns + "Target",new XAttribute("Name","WriteProperty"), new XAttribute("BeforeTargets", "AfterBuild"),
236+
new XElement(ns + "ItemGroup",
237+
propertiesElements),
238+
new XElement(ns + "WriteLinesToFile",
239+
new XAttribute("File", @"$(BaseIntermediateOutputPath)\$(Configuration)\$(TargetFramework)\PropertyValues.txt"),
240+
new XAttribute("Lines", "@(LinesToWrite)"),
241+
new XAttribute("Overwrite","true"),
242+
new XAttribute("Encoding","Unicode")));
243+
244+
245+
project.Root.AddFirst(newNode);
246+
}
247+
}
248+
249+
public Dictionary<string, string> GetPropertyValues(string testRoot, string project, string configuration = "Debug", string targetFramework = null)
250+
{
251+
var propertyValues = new Dictionary<string, string>();
252+
253+
string intermediateOutputPath = Path.Combine(testRoot, project, "obj", configuration, targetFramework ?? "foo");
254+
255+
foreach (var line in File.ReadAllLines(Path.Combine(intermediateOutputPath, "PropertyValues.txt")))
256+
{
257+
int colonIndex = line.IndexOf(':');
258+
if (colonIndex > 0)
259+
{
260+
string propertyName = line.Substring(0, colonIndex);
261+
string propertyValue = line.Length == colonIndex + 1 ? "" : line.Substring(colonIndex + 2);
262+
propertyValues[propertyName] = propertyValue;
263+
}
264+
}
265+
266+
return propertyValues;
267+
}
169268
}
170269
}

src/Tests/Microsoft.NET.Pack.Tests/GivenThatWeWantToPackACppCliProject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public GivenThatWeWantToPackACppCliProject(ITestOutputHelper log) : base(log)
1818
{
1919
}
2020

21-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/11008")]
21+
[FullMSBuildOnlyFact]
2222
public void It_cannot_pack_the_cppcliproject()
2323
{
2424
var testAsset = _testAssetsManager

0 commit comments

Comments
 (0)