Skip to content

Commit e0390ce

Browse files
authored
Reenable a skipped cppcli test. (#31386)
2 parents b488cef + dadfe89 commit e0390ce

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<Keyword>ManagedCProj</Keyword>
1818
<RootNamespace>NETCoreCppCliTest</RootNamespace>
1919
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
20+
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
2021
</PropertyGroup>
2122
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2223
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public void It_builds_and_runs()
3131
var testAsset = _testAssetsManager
3232
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
3333
.WithSource()
34-
.WithProjectChanges((projectPath, project) => AddPackageReference(projectPath, project, "NewtonSoft.Json", "13.0.1"))
3534
.WithProjectChanges((projectPath, project) => AddBuildProperty(projectPath, project, "EnableManagedpackageReferenceSupport", "true"));
3635

3736
// build projects separately with BuildProjectReferences=false to simulate VS build behavior
@@ -69,7 +68,7 @@ public void It_builds_and_runs_with_package_reference()
6968
var testAsset = _testAssetsManager
7069
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
7170
.WithSource()
72-
.WithProjectChanges((projectPath, project) => ConfigureProject(projectPath, project, "NewtonSoft.Json", "13.0.1", targetFramework, new string[] { "_EnablePackageReferencesInVCProjects", "IncludeWindowsSDKRefFrameworkReferences" }));
71+
.WithProjectChanges((projectPath, project) => ConfigureProject(projectPath, project, targetFramework, new string[] { "_EnablePackageReferencesInVCProjects", "IncludeWindowsSDKRefFrameworkReferences" }));
7372

7473
new BuildCommand(testAsset, "NETCoreCppCliTest")
7574
.Execute("-p:Platform=x64")
@@ -87,7 +86,6 @@ public void Given_no_restore_It_builds_cpp_project()
8786
var testAsset = _testAssetsManager
8887
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
8988
.WithSource()
90-
.WithProjectChanges((projectPath, project) => AddPackageReference(projectPath, project, "NewtonSoft.Json", "13.0.1"))
9189
.WithProjectChanges((projectPath, project) => AddBuildProperty(projectPath, project, "EnableManagedpackageReferenceSupport", "True")); ;
9290

9391
new BuildCommand(testAsset, "NETCoreCppCliTest")
@@ -101,8 +99,7 @@ public void Given_Wpf_framework_reference_It_builds_cpp_project()
10199
{
102100
var testAsset = _testAssetsManager
103101
.CopyTestAsset("CppCliLibWithWpfFrameworkReference")
104-
.WithSource()
105-
.WithProjectChanges((projectPath, project) => AddPackageReference(projectPath, project, "NewtonSoft.Json", "13.0.1"));
102+
.WithSource();
106103

107104
new BuildCommand(testAsset)
108105
.Execute("-p:Platform=x64")
@@ -199,25 +196,13 @@ private void ChangeTargetFramework(string projectPath, XDocument project, string
199196
}
200197
}
201198

202-
private void ConfigureProject(string projectPath, XDocument project, string package, string version, string targetFramework, string[] properties)
199+
private void ConfigureProject(string projectPath, XDocument project, string targetFramework, string[] properties)
203200
{
204201
AddBuildProperty(projectPath, project, "EnableManagedpackageReferenceSupport","true");
205202
ChangeTargetFramework(projectPath, project, targetFramework);
206-
AddPackageReference(projectPath, project, package, version);
207203
RecordProperties(projectPath, project, properties);
208204
}
209205

210-
private void AddPackageReference(string projectPath, XDocument project, string package, string version)
211-
{
212-
if (Path.GetExtension(projectPath) == ".vcxproj")
213-
{
214-
XNamespace ns = project.Root.Name.Namespace;
215-
XElement itemGroup = project.Root.Descendants(ns + "ItemGroup").First();
216-
itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", package),
217-
new XAttribute("Version", version)));
218-
219-
}
220-
}
221206
private void AddBuildProperty(string projectPath, XDocument project, string property, string value)
222207
{
223208
if (Path.GetExtension(projectPath) == ".vcxproj")

src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishACppCliProject.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.IO;
55
using System.Linq;
6+
using System.Xml.Linq;
67
using FluentAssertions;
78
using Microsoft.NET.Build.Tasks;
89
using Microsoft.NET.TestFramework;
@@ -20,22 +21,22 @@ public GivenThatWeWantToPublishACppCliProject(ITestOutputHelper log) : base(log)
2021
{
2122
}
2223

23-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/3785")]
24+
[FullMSBuildOnlyFact]
2425
public void When_referenced_by_csharp_project_it_publishes_and_runs()
2526
{
2627
var testAsset = _testAssetsManager
2728
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
2829
.WithSource();
2930

3031
new PublishCommand(Log, Path.Combine(testAsset.TestRoot, "CSConsoleApp"))
31-
.Execute(new string[] { "-p:Platform=x64" })
32+
.Execute(new string[] { "-p:Platform=x64", "-p:EnableManagedpackageReferenceSupport=true" })
3233
.Should()
3334
.Pass();
3435

3536
var exe = Path.Combine( //find the platform directory
3637
new DirectoryInfo(Path.Combine(testAsset.TestRoot, "CSConsoleApp", "bin")).GetDirectories().Single().FullName,
3738
"Debug",
38-
"netcoreapp3.1",
39+
ToolsetInfo.CurrentTargetFramework,
3940
"publish",
4041
"CSConsoleApp.exe");
4142

@@ -48,15 +49,15 @@ public void When_referenced_by_csharp_project_it_publishes_and_runs()
4849
.HaveStdOutContaining("Hello, World!");
4950
}
5051

51-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/3785")]
52+
[FullMSBuildOnlyFact(Skip = "There is no publish error when using PackageReference support which is required for testing")]
5253
public void When_not_referenced_by_csharp_project_it_fails_to_publish()
5354
{
5455
var testAsset = _testAssetsManager
5556
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
5657
.WithSource();
5758

5859
new PublishCommand(Log, Path.Combine(testAsset.TestRoot, "NETCoreCppCliTest"))
59-
.Execute(new string[] { "-p:Platform=x64" })
60+
.Execute(new string[] { "-p:Platform=x64", "-p:EnableManagedpackageReferenceSupport=true"})
6061
.Should()
6162
.Fail()
6263
.And.HaveStdOutContaining(Strings.NoSupportCppPublishDotnetCore);

0 commit comments

Comments
 (0)