Skip to content

Commit a8daad6

Browse files
authored
Merge pull request #28596 from dotnet/marcpopMSFT-disablewindowsdkforc++
Disable the windows SDK automated references for c++
2 parents cd16c47 + cd4d6e2 commit a8daad6

File tree

9 files changed

+112
-19
lines changed

9 files changed

+112
-19
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/NetCoreCppCliLibWithTransitiveDeps/NETCoreCppCliTest/NETCoreCppCliTest.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<PropertyGroup Label="Globals">
3838
<VCProjectVersion>16.0</VCProjectVersion>
3939
<ProjectGuid>{CF5DA8D7-1FDF-4E8F-AFE6-450BE16E906A}</ProjectGuid>
40-
<TargetFramework>net5.0</TargetFramework>
40+
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
4141
<Keyword>ManagedCProj</Keyword>
4242
<EnableDynamicLoading>true</EnableDynamicLoading>
4343
<RootNamespace>NETCoreCppCliTest</RootNamespace>

src/Assets/TestProjects/NetCoreCppCliLibWithTransitiveDeps/NETCoreCppCliTestB/NETCoreCppCliTestB.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<PropertyGroup Label="Globals">
3838
<VCProjectVersion>16.0</VCProjectVersion>
3939
<ProjectGuid>{C8D22D0F-0C2D-4B4A-BF28-14A2D001102B}</ProjectGuid>
40-
<TargetFramework>net5.0</TargetFramework>
40+
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
4141
<Keyword>ManagedCProj</Keyword>
4242
<EnableDynamicLoading>true</EnableDynamicLoading>
4343
<RootNamespace>NETCoreCppCliTest</RootNamespace>

src/Assets/TestProjects/NetCoreCppCliLibWithTransitiveDeps/NETCoreCppCliTestC/NETCoreCppCliTestC.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<PropertyGroup Label="Globals">
3838
<VCProjectVersion>16.0</VCProjectVersion>
3939
<ProjectGuid>{73B24404-97DE-467A-8251-6542819BCEB4}</ProjectGuid>
40-
<TargetFramework>net5.0</TargetFramework>
40+
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
4141
<Keyword>ManagedCProj</Keyword>
4242
<EnableDynamicLoading>true</EnableDynamicLoading>
4343
<RootNamespace>NETCoreCppCliTest</RootNamespace>

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>$(CurrentTargetFramework)</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>$(CurrentTargetFramework)</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/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Windows.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Copyright (c) .NET Foundation. All rights reserved.
1919
and '$(TargetPlatformIdentifier)' == 'Windows'
2020
and '$(TargetPlatformVersion)' != ''
2121
and $([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '10.0'))
22-
and ('$(Language)' != 'C++' or '$(_EnablePackageReferencesInVCProjects)' == 'true')
22+
and '$(Language)' != 'C++'
2323
and '$(IncludeWindowsSDKRefFrameworkReferences)' == ''">
2424
<IncludeWindowsSDKRefFrameworkReferences>true</IncludeWindowsSDKRefFrameworkReferences>
2525
</PropertyGroup>

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

Lines changed: 101 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,26 @@ 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+
new BuildCommand(testAsset, "NETCoreCppCliTest")
70+
.Execute("-p:Platform=x64", "-p:EnableManagedpackageReferenceSupport=true")
71+
.Should()
72+
.Pass();
73+
74+
var cppnProjProperties = GetPropertyValues(testAsset.TestRoot, "NETCoreCppCliTest", targetFramework: targetFramework);
75+
Assert.True(cppnProjProperties["_EnablePackageReferencesInVCProjects"] == "true");
76+
Assert.True(cppnProjProperties["IncludeWindowsSDKRefFrameworkReferences"] == "");
77+
}
78+
79+
[FullMSBuildOnlyFact]
5680
public void Given_no_restore_It_builds_cpp_project()
5781
{
5882
var testAsset = _testAssetsManager
@@ -65,7 +89,7 @@ public void Given_no_restore_It_builds_cpp_project()
6589
.Pass();
6690
}
6791

68-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/3785")]
92+
[FullMSBuildOnlyFact]
6993
public void Given_Wpf_framework_reference_It_builds_cpp_project()
7094
{
7195
var testAsset = _testAssetsManager
@@ -78,7 +102,7 @@ public void Given_Wpf_framework_reference_It_builds_cpp_project()
78102
.Pass();
79103
}
80104

81-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/11008")]
105+
[FullMSBuildOnlyFact]
82106
public void It_fails_with_error_message_on_EnableComHosting()
83107
{
84108
var testAsset = _testAssetsManager
@@ -106,7 +130,7 @@ public void It_fails_with_error_message_on_EnableComHosting()
106130
.HaveStdOutContaining(Strings.NoSupportCppEnableComHosting);
107131
}
108132

109-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/11008")]
133+
[FullMSBuildOnlyFact]
110134
public void It_fails_with_error_message_on_fullframework()
111135
{
112136
var testAsset = _testAssetsManager
@@ -123,7 +147,7 @@ public void It_fails_with_error_message_on_fullframework()
123147
.HaveStdOutContaining(Strings.NETFrameworkWithoutUsingNETSdkDefaults);
124148
}
125149

126-
[FullMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/11008")]
150+
[FullMSBuildOnlyFact]
127151
public void It_fails_with_error_message_on_tfm_lower_than_3_1()
128152
{
129153
var testAsset = _testAssetsManager
@@ -140,7 +164,7 @@ public void It_fails_with_error_message_on_tfm_lower_than_3_1()
140164
.HaveStdOutContaining(Strings.CppRequiresTFMVersion31);
141165
}
142166

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

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)