Skip to content

Commit dadfe89

Browse files
committed
Switch to setting RestoreProjectStyle in the test application for cppcli PackageReference tests
1 parent 1072f34 commit dadfe89

File tree

3 files changed

+6
-34
lines changed

3 files changed

+6
-34
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
@@ -67,7 +66,7 @@ public void It_builds_and_runs_with_package_reference()
6766
var testAsset = _testAssetsManager
6867
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
6968
.WithSource()
70-
.WithProjectChanges((projectPath, project) => ConfigureProject(projectPath, project, "NewtonSoft.Json", "13.0.1", targetFramework, new string[] { "_EnablePackageReferencesInVCProjects", "IncludeWindowsSDKRefFrameworkReferences" }));
69+
.WithProjectChanges((projectPath, project) => ConfigureProject(projectPath, project, targetFramework, new string[] { "_EnablePackageReferencesInVCProjects", "IncludeWindowsSDKRefFrameworkReferences" }));
7170

7271
new BuildCommand(testAsset, "NETCoreCppCliTest")
7372
.Execute("-p:Platform=x64")
@@ -85,7 +84,6 @@ public void Given_no_restore_It_builds_cpp_project()
8584
var testAsset = _testAssetsManager
8685
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
8786
.WithSource()
88-
.WithProjectChanges((projectPath, project) => AddPackageReference(projectPath, project, "NewtonSoft.Json", "13.0.1"))
8987
.WithProjectChanges((projectPath, project) => AddBuildProperty(projectPath, project, "EnableManagedpackageReferenceSupport", "True")); ;
9088

9189
new BuildCommand(testAsset, "NETCoreCppCliTest")
@@ -99,8 +97,7 @@ public void Given_Wpf_framework_reference_It_builds_cpp_project()
9997
{
10098
var testAsset = _testAssetsManager
10199
.CopyTestAsset("CppCliLibWithWpfFrameworkReference")
102-
.WithSource()
103-
.WithProjectChanges((projectPath, project) => AddPackageReference(projectPath, project, "NewtonSoft.Json", "13.0.1"));
100+
.WithSource();
104101

105102
new BuildCommand(testAsset)
106103
.Execute("-p:Platform=x64")
@@ -197,25 +194,13 @@ private void ChangeTargetFramework(string projectPath, XDocument project, string
197194
}
198195
}
199196

200-
private void ConfigureProject(string projectPath, XDocument project, string package, string version, string targetFramework, string[] properties)
197+
private void ConfigureProject(string projectPath, XDocument project, string targetFramework, string[] properties)
201198
{
202199
AddBuildProperty(projectPath, project, "EnableManagedpackageReferenceSupport","true");
203200
ChangeTargetFramework(projectPath, project, targetFramework);
204-
AddPackageReference(projectPath, project, package, version);
205201
RecordProperties(projectPath, project, properties);
206202
}
207203

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

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public void When_referenced_by_csharp_project_it_publishes_and_runs()
2626
{
2727
var testAsset = _testAssetsManager
2828
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
29-
.WithSource()
30-
.WithProjectChanges((projectPath, project) => AddPackageReference(projectPath, project, "NewtonSoft.Json", "13.0.1"));
29+
.WithSource();
3130

3231
new PublishCommand(Log, Path.Combine(testAsset.TestRoot, "CSConsoleApp"))
3332
.Execute(new string[] { "-p:Platform=x64", "-p:EnableManagedpackageReferenceSupport=true" })
@@ -55,26 +54,13 @@ public void When_not_referenced_by_csharp_project_it_fails_to_publish()
5554
{
5655
var testAsset = _testAssetsManager
5756
.CopyTestAsset("NetCoreCsharpAppReferenceCppCliLib")
58-
.WithSource()
59-
.WithProjectChanges((projectPath, project) => AddPackageReference(projectPath, project, "NewtonSoft.Json", "13.0.1"));
57+
.WithSource();
6058

6159
new PublishCommand(Log, Path.Combine(testAsset.TestRoot, "NETCoreCppCliTest"))
6260
.Execute(new string[] { "-p:Platform=x64", "-p:EnableManagedpackageReferenceSupport=true"})
6361
.Should()
6462
.Fail()
6563
.And.HaveStdOutContaining(Strings.NoSupportCppPublishDotnetCore);
6664
}
67-
68-
private void AddPackageReference(string projectPath, XDocument project, string package, string version)
69-
{
70-
if (Path.GetExtension(projectPath) == ".vcxproj")
71-
{
72-
XNamespace ns = project.Root.Name.Namespace;
73-
XElement itemGroup = project.Root.Descendants(ns + "ItemGroup").First();
74-
itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", package),
75-
new XAttribute("Version", version)));
76-
77-
}
78-
}
7965
}
8066
}

0 commit comments

Comments
 (0)