1
1
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
+ using System ;
5
+ using System . Collections . Generic ;
4
6
using System . IO ;
5
7
using System . Linq ;
8
+ using System . Security . Cryptography ;
6
9
using System . Xml . Linq ;
7
10
using FluentAssertions ;
8
11
using Microsoft . NET . Build . Tasks ;
9
12
using Microsoft . NET . TestFramework ;
10
13
using Microsoft . NET . TestFramework . Assertions ;
11
14
using Microsoft . NET . TestFramework . Commands ;
15
+ using Microsoft . NET . TestFramework . ProjectConstruction ;
16
+ using Xunit ;
12
17
using Xunit . Abstractions ;
13
18
14
19
namespace Microsoft . NET . Build . Tests
@@ -19,7 +24,7 @@ public GivenThatWeWantToBuildACppCliProject(ITestOutputHelper log) : base(log)
19
24
{
20
25
}
21
26
22
- [ FullMSBuildOnlyFact ( Skip = "https://github.com/dotnet/sdk/issues/3785" ) ]
27
+ [ FullMSBuildOnlyFact ]
23
28
public void It_builds_and_runs ( )
24
29
{
25
30
var testAsset = _testAssetsManager
@@ -40,7 +45,7 @@ public void It_builds_and_runs()
40
45
var exe = Path . Combine ( //find the platform directory
41
46
new DirectoryInfo ( Path . Combine ( testAsset . TestRoot , "CSConsoleApp" , "bin" ) ) . GetDirectories ( ) . Single ( ) . FullName ,
42
47
"Debug" ,
43
- "net5.0" ,
48
+ ToolsetInfo . CurrentTargetFramework ,
44
49
"CSConsoleApp.exe" ) ;
45
50
46
51
var runCommand = new RunExeCommand ( Log , exe ) ;
@@ -52,7 +57,26 @@ public void It_builds_and_runs()
52
57
. HaveStdOutContaining ( "Hello, World!" ) ;
53
58
}
54
59
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 ]
56
80
public void Given_no_restore_It_builds_cpp_project ( )
57
81
{
58
82
var testAsset = _testAssetsManager
@@ -65,7 +89,7 @@ public void Given_no_restore_It_builds_cpp_project()
65
89
. Pass ( ) ;
66
90
}
67
91
68
- [ FullMSBuildOnlyFact ( Skip = "https://github.com/dotnet/sdk/issues/3785" ) ]
92
+ [ FullMSBuildOnlyFact ]
69
93
public void Given_Wpf_framework_reference_It_builds_cpp_project ( )
70
94
{
71
95
var testAsset = _testAssetsManager
@@ -78,7 +102,7 @@ public void Given_Wpf_framework_reference_It_builds_cpp_project()
78
102
. Pass ( ) ;
79
103
}
80
104
81
- [ FullMSBuildOnlyFact ( Skip = "https://github.com/dotnet/sdk/issues/11008" ) ]
105
+ [ FullMSBuildOnlyFact ]
82
106
public void It_fails_with_error_message_on_EnableComHosting ( )
83
107
{
84
108
var testAsset = _testAssetsManager
@@ -106,7 +130,7 @@ public void It_fails_with_error_message_on_EnableComHosting()
106
130
. HaveStdOutContaining ( Strings . NoSupportCppEnableComHosting ) ;
107
131
}
108
132
109
- [ FullMSBuildOnlyFact ( Skip = "https://github.com/dotnet/sdk/issues/11008" ) ]
133
+ [ FullMSBuildOnlyFact ]
110
134
public void It_fails_with_error_message_on_fullframework ( )
111
135
{
112
136
var testAsset = _testAssetsManager
@@ -123,7 +147,7 @@ public void It_fails_with_error_message_on_fullframework()
123
147
. HaveStdOutContaining ( Strings . NETFrameworkWithoutUsingNETSdkDefaults ) ;
124
148
}
125
149
126
- [ FullMSBuildOnlyFact ( Skip = "https://github.com/dotnet/sdk/issues/11008" ) ]
150
+ [ FullMSBuildOnlyFact ]
127
151
public void It_fails_with_error_message_on_tfm_lower_than_3_1 ( )
128
152
{
129
153
var testAsset = _testAssetsManager
@@ -140,7 +164,7 @@ public void It_fails_with_error_message_on_tfm_lower_than_3_1()
140
164
. HaveStdOutContaining ( Strings . CppRequiresTFMVersion31 ) ;
141
165
}
142
166
143
- [ FullMSBuildOnlyFact ( Skip = "https://github.com/dotnet/sdk/issues/11008" ) ]
167
+ [ FullMSBuildOnlyFact ]
144
168
public void When_run_with_selfcontained_It_fails_with_error_message ( )
145
169
{
146
170
var testAsset = _testAssetsManager
@@ -166,5 +190,74 @@ private void ChangeTargetFramework(string projectPath, XDocument project, string
166
190
. Single ( ) . Value = targetFramework ;
167
191
}
168
192
}
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
+ }
169
262
}
170
263
}
0 commit comments