@@ -76,50 +76,52 @@ private void CreateProjects()
76
76
MainProject . ReferencedProjects . Add ( ReferencedProject ) ;
77
77
}
78
78
79
- private void RunTest ( bool referencedExeShouldRun , [ CallerMemberName ] string callingMethod = null )
79
+ private void RunTest ( string buildFailureCode = null , [ CallerMemberName ] string callingMethod = null )
80
80
{
81
81
var testProjectInstance = _testAssetsManager . CreateTestProject ( MainProject , callingMethod : callingMethod , identifier : MainSelfContained . ToString ( ) + "_" + ReferencedSelfContained . ToString ( ) ) ;
82
82
83
83
string outputDirectory ;
84
84
85
+ TestCommand buildOrPublishCommand ;
86
+
85
87
if ( TestWithPublish )
86
88
{
87
89
var publishCommand = new PublishCommand ( testProjectInstance ) ;
88
90
89
- publishCommand . Execute ( )
90
- . Should ( )
91
- . Pass ( ) ;
92
-
93
91
outputDirectory = publishCommand . GetOutputDirectory ( MainProject . TargetFrameworks , runtimeIdentifier : MainProject . RuntimeIdentifier ) . FullName ;
92
+
93
+ buildOrPublishCommand = publishCommand ;
94
94
}
95
95
else
96
96
{
97
97
var buildCommand = new BuildCommand ( testProjectInstance ) ;
98
98
99
- buildCommand . Execute ( )
100
- . Should ( )
101
- . Pass ( ) ;
102
-
103
99
outputDirectory = buildCommand . GetOutputDirectory ( MainProject . TargetFrameworks , runtimeIdentifier : MainProject . RuntimeIdentifier ) . FullName ;
100
+
101
+ buildOrPublishCommand = buildCommand ;
104
102
}
105
103
106
- var mainExePath = Path . Combine ( outputDirectory , MainProject . Name + Constants . ExeSuffix ) ;
104
+ if ( buildFailureCode == null )
105
+ {
106
+ buildOrPublishCommand . Execute ( )
107
+ . Should ( )
108
+ . Pass ( ) ;
107
109
108
- var referencedExePath = Path . Combine ( outputDirectory , ReferencedProject . Name + Constants . ExeSuffix ) ;
110
+ var mainExePath = Path . Combine ( outputDirectory , MainProject . Name + Constants . ExeSuffix ) ;
109
111
110
- new RunExeCommand ( Log , mainExePath )
111
- . Execute ( )
112
- . Should ( )
113
- . Pass ( )
114
- . And
115
- . HaveStdOut ( "Main project" ) ;
112
+ var referencedExePath = Path . Combine ( outputDirectory , ReferencedProject . Name + Constants . ExeSuffix ) ;
116
113
114
+ new RunExeCommand ( Log , mainExePath )
115
+ . Execute ( )
116
+ . Should ( )
117
+ . Pass ( )
118
+ . And
119
+ . HaveStdOut ( "Main project" ) ;
117
120
118
- var referencedExeResult = new RunExeCommand ( Log , referencedExePath )
119
- . Execute ( ) ;
120
121
121
- if ( referencedExeShouldRun )
122
- {
122
+ var referencedExeResult = new RunExeCommand ( Log , referencedExePath )
123
+ . Execute ( ) ;
124
+
123
125
referencedExeResult
124
126
. Should ( )
125
127
. Pass ( )
@@ -128,13 +130,15 @@ private void RunTest(bool referencedExeShouldRun, [CallerMemberName] string call
128
130
}
129
131
else
130
132
{
131
- referencedExeResult
133
+ // Build should not succeed
134
+ buildOrPublishCommand . Execute ( )
132
135
. Should ( )
133
- . Fail ( ) ;
134
- }
136
+ . Fail ( )
137
+ . And
138
+ . HaveStdOutContaining ( buildFailureCode ) ;
139
+ }
135
140
}
136
141
137
-
138
142
[ Theory ]
139
143
[ InlineData ( false , false ) ]
140
144
[ InlineData ( true , true ) ]
@@ -145,7 +149,7 @@ public void ReferencedExeCanRun(bool mainSelfContained, bool referencedSelfConta
145
149
146
150
CreateProjects ( ) ;
147
151
148
- RunTest ( true ) ;
152
+ RunTest ( ) ;
149
153
}
150
154
151
155
[ Fact ]
@@ -159,22 +163,64 @@ public void ReferencedExeWithLowerTargetFrameworkCanRun()
159
163
ReferencedProject . TargetFrameworks = "netcoreapp3.1" ;
160
164
ReferencedProject . AdditionalProperties [ "LangVersion" ] = "9.0" ;
161
165
162
- RunTest ( true ) ;
166
+ RunTest ( ) ;
163
167
}
164
168
165
169
// Having a self-contained and a framework-dependent app in the same folder is not supported (due to the way the host works).
166
170
// The referenced app will fail to run. See here for more details: https://github.com/dotnet/sdk/pull/14488#issuecomment-725406998
167
171
[ Theory ]
168
- [ InlineData ( true , false ) ]
169
- [ InlineData ( false , true ) ]
170
- public void ReferencedExeFailsToRun ( bool mainSelfContained , bool referencedSelfContained )
172
+ [ InlineData ( true , false , "NETSDK1150" ) ]
173
+ [ InlineData ( false , true , "NETSDK1151" ) ]
174
+ public void ReferencedExeFailsToBuild ( bool mainSelfContained , bool referencedSelfContained , string expectedFailureCode )
171
175
{
172
176
MainSelfContained = mainSelfContained ;
173
177
ReferencedSelfContained = referencedSelfContained ;
174
178
175
179
CreateProjects ( ) ;
176
180
177
- RunTest ( referencedExeShouldRun : false ) ;
181
+ RunTest ( expectedFailureCode ) ;
182
+ }
183
+
184
+ [ Fact ]
185
+ public void ReferencedExeCanRunWhenReferencesExeWithSelfContainedMismatchForDifferentTargetFramework ( )
186
+ {
187
+ MainSelfContained = true ;
188
+ ReferencedSelfContained = false ;
189
+
190
+ CreateProjects ( ) ;
191
+
192
+ // Reference project which is self-contained for net5.0, not self-contained for net5.0-windows.
193
+ ReferencedProject . TargetFrameworks = "net5.0;net5.0-windows" ;
194
+ ReferencedProject . ProjectChanges . Add ( project =>
195
+ {
196
+ var ns = project . Root . Name . Namespace ;
197
+
198
+ project . Root . Element ( ns + "PropertyGroup" )
199
+ . Add ( XElement . Parse ( @"<RuntimeIdentifier Condition=""'$(TargetFramework)' == 'net5.0'"">" + EnvironmentInfo . GetCompatibleRid ( ) + "</RuntimeIdentifier>" ) ) ;
200
+ } ) ;
201
+
202
+ RunTest ( ) ;
203
+ }
204
+
205
+ [ Fact ]
206
+ public void ReferencedExeFailsToBuildWhenReferencesExeWithSelfContainedMismatchForSameTargetFramework ( )
207
+ {
208
+ MainSelfContained = true ;
209
+ ReferencedSelfContained = false ;
210
+
211
+ CreateProjects ( ) ;
212
+
213
+ // Reference project which is self-contained for net5.0-windows, not self-contained for net5.0.
214
+ ReferencedProject . TargetFrameworks = "net5.0;net5.0-windows" ;
215
+ ReferencedProject . ProjectChanges . Add ( project =>
216
+ {
217
+ var ns = project . Root . Name . Namespace ;
218
+
219
+ project . Root . Element ( ns + "PropertyGroup" )
220
+ . Add ( XElement . Parse ( @"<RuntimeIdentifier Condition=""'$(TargetFramework)' == 'net5.0-windows'"">" + EnvironmentInfo . GetCompatibleRid ( ) + "</RuntimeIdentifier>" ) ) ;
221
+ } ) ;
222
+
223
+ RunTest ( "NETSDK1150" ) ;
178
224
}
179
225
180
226
[ Theory ]
@@ -189,7 +235,7 @@ public void ReferencedExeCanRunWhenPublished(bool selfContained)
189
235
190
236
CreateProjects ( ) ;
191
237
192
- RunTest ( referencedExeShouldRun : true ) ;
238
+ RunTest ( ) ;
193
239
}
194
240
195
241
[ Fact ]
@@ -211,7 +257,7 @@ public void ReferencedExeCanRunWhenPublishedWithTrimming()
211
257
ReferencedProject . AdditionalProperties [ "PublishTrimmed" ] = "True" ;
212
258
}
213
259
214
- RunTest ( referencedExeShouldRun : true ) ;
260
+ RunTest ( ) ;
215
261
}
216
262
}
217
263
}
0 commit comments