@@ -1098,14 +1098,17 @@ public void Publish()
1098
1098
var artifactsDir = VirtualProjectBuildingCommand . GetArtifactsPath ( programFile ) ;
1099
1099
if ( Directory . Exists ( artifactsDir ) ) Directory . Delete ( artifactsDir , recursive : true ) ;
1100
1100
1101
+ var publishDir = Path . Join ( testInstance . Path , "artifacts" ) ;
1102
+ if ( Directory . Exists ( publishDir ) ) Directory . Delete ( publishDir , recursive : true ) ;
1103
+
1101
1104
new DotnetCommand ( Log , "publish" , "Program.cs" )
1102
1105
. WithWorkingDirectory ( testInstance . Path )
1103
1106
. Execute ( )
1104
1107
. Should ( ) . Pass ( ) ;
1105
1108
1106
- new DirectoryInfo ( artifactsDir ) . Sub ( "publish/release " )
1109
+ new DirectoryInfo ( publishDir ) . Sub ( "Program " )
1107
1110
. Should ( ) . Exist ( )
1108
- . And . NotHaveFile ( "Program .deps.json") ; // no deps.json file for AOT-published app
1111
+ . And . NotHaveFilesMatching ( "* .deps.json", SearchOption . TopDirectoryOnly ) ; // no deps.json file for AOT-published app
1109
1112
}
1110
1113
1111
1114
[ Fact ]
@@ -1118,18 +1121,112 @@ public void Publish_Options()
1118
1121
var artifactsDir = VirtualProjectBuildingCommand . GetArtifactsPath ( programFile ) ;
1119
1122
if ( Directory . Exists ( artifactsDir ) ) Directory . Delete ( artifactsDir , recursive : true ) ;
1120
1123
1124
+ var publishDir = Path . Join ( testInstance . Path , "artifacts" ) ;
1125
+ if ( Directory . Exists ( publishDir ) ) Directory . Delete ( publishDir , recursive : true ) ;
1126
+
1121
1127
new DotnetCommand ( Log , "publish" , "Program.cs" , "-c" , "Debug" , "-p:PublishAot=false" , "-bl" )
1122
1128
. WithWorkingDirectory ( testInstance . Path )
1123
1129
. Execute ( )
1124
1130
. Should ( ) . Pass ( ) ;
1125
1131
1126
- new DirectoryInfo ( artifactsDir ) . Sub ( "publish/debug " )
1132
+ new DirectoryInfo ( publishDir ) . Sub ( "Program " )
1127
1133
. Should ( ) . Exist ( )
1128
1134
. And . HaveFile ( "Program.deps.json" ) ;
1129
1135
1130
1136
new DirectoryInfo ( testInstance . Path ) . File ( "msbuild.binlog" ) . Should ( ) . Exist ( ) ;
1131
1137
}
1132
1138
1139
+ [ Fact ]
1140
+ public void Publish_PublishDir_IncludesFileName ( )
1141
+ {
1142
+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1143
+ var programFile = Path . Join ( testInstance . Path , "MyCustomProgram.cs" ) ;
1144
+ File . WriteAllText ( programFile , s_program ) ;
1145
+
1146
+ var artifactsDir = VirtualProjectBuildingCommand . GetArtifactsPath ( programFile ) ;
1147
+ if ( Directory . Exists ( artifactsDir ) ) Directory . Delete ( artifactsDir , recursive : true ) ;
1148
+
1149
+ var publishDir = Path . Join ( testInstance . Path , "artifacts" ) ;
1150
+ if ( Directory . Exists ( publishDir ) ) Directory . Delete ( publishDir , recursive : true ) ;
1151
+
1152
+ new DotnetCommand ( Log , "publish" , "MyCustomProgram.cs" )
1153
+ . WithWorkingDirectory ( testInstance . Path )
1154
+ . Execute ( )
1155
+ . Should ( ) . Pass ( ) ;
1156
+
1157
+ new DirectoryInfo ( publishDir ) . Sub ( "MyCustomProgram" )
1158
+ . Should ( ) . Exist ( )
1159
+ . And . NotHaveFilesMatching ( "*.deps.json" , SearchOption . TopDirectoryOnly ) ; // no deps.json file for AOT-published app
1160
+ }
1161
+
1162
+ [ Fact ]
1163
+ public void Publish_PublishDir_CommandLine ( )
1164
+ {
1165
+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1166
+ var programFile = Path . Join ( testInstance . Path , "Program.cs" ) ;
1167
+ File . WriteAllText ( programFile , s_program ) ;
1168
+
1169
+ var customPublishDir = Path . Join ( testInstance . Path , "custom-publish" ) ;
1170
+ if ( Directory . Exists ( customPublishDir ) ) Directory . Delete ( customPublishDir , recursive : true ) ;
1171
+
1172
+ new DotnetCommand ( Log , "publish" , "Program.cs" , $ "/p:PublishDir={ customPublishDir } ")
1173
+ . WithWorkingDirectory ( testInstance . Path )
1174
+ . Execute ( )
1175
+ . Should ( ) . Pass ( ) ;
1176
+
1177
+ new DirectoryInfo ( customPublishDir )
1178
+ . Should ( ) . Exist ( )
1179
+ . And . NotHaveFilesMatching ( "*.deps.json" , SearchOption . TopDirectoryOnly ) ; // no deps.json file for AOT-published app
1180
+ }
1181
+
1182
+ [ Fact ]
1183
+ public void Publish_PublishDir_PropertyDirective ( )
1184
+ {
1185
+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1186
+ var programFile = Path . Join ( testInstance . Path , "Program.cs" ) ;
1187
+ var publishDir = Path . Join ( testInstance . Path , "directive-publish" ) ;
1188
+ File . WriteAllText ( programFile , $ """
1189
+ #:property PublishDir={ publishDir }
1190
+ { s_program }
1191
+ """ ) ;
1192
+
1193
+ if ( Directory . Exists ( publishDir ) ) Directory . Delete ( publishDir , recursive : true ) ;
1194
+
1195
+ new DotnetCommand ( Log , "publish" , "Program.cs" )
1196
+ . WithWorkingDirectory ( testInstance . Path )
1197
+ . Execute ( )
1198
+ . Should ( ) . Pass ( ) ;
1199
+
1200
+ new DirectoryInfo ( publishDir )
1201
+ . Should ( ) . Exist ( )
1202
+ . And . NotHaveFilesMatching ( "*.deps.json" , SearchOption . TopDirectoryOnly ) ; // no deps.json file for AOT-published app
1203
+ }
1204
+
1205
+ [ Fact ]
1206
+ public void Publish_In_SubDir ( )
1207
+ {
1208
+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1209
+ var subDir = Directory . CreateDirectory ( Path . Combine ( testInstance . Path , "subdir" ) ) ;
1210
+
1211
+ var programFile = Path . Join ( subDir . FullName , "Program.cs" ) ;
1212
+ File . WriteAllText ( programFile , s_program ) ;
1213
+
1214
+ var artifactsDir = VirtualProjectBuildingCommand . GetArtifactsPath ( programFile ) ;
1215
+ if ( Directory . Exists ( artifactsDir ) ) Directory . Delete ( artifactsDir , recursive : true ) ;
1216
+
1217
+ var publishDir = Path . Join ( subDir . FullName , "artifacts" ) ;
1218
+ if ( Directory . Exists ( publishDir ) ) Directory . Delete ( publishDir , recursive : true ) ;
1219
+
1220
+ new DotnetCommand ( Log , "publish" , "./subdir/Program.cs" )
1221
+ . WithWorkingDirectory ( testInstance . Path )
1222
+ . Execute ( )
1223
+ . Should ( ) . Pass ( ) ;
1224
+
1225
+ new DirectoryInfo ( testInstance . Path ) . Sub ( "subdir" ) . Sub ( "artifacts" ) . Sub ( "Program" )
1226
+ . Should ( ) . Exist ( )
1227
+ . And . NotHaveFilesMatching ( "*.deps.json" , SearchOption . TopDirectoryOnly ) ; // no deps.json file for AOT-published app
1228
+ }
1229
+
1133
1230
[ PlatformSpecificFact ( TestPlatforms . AnyUnix ) , UnsupportedOSPlatform ( "windows" ) ]
1134
1231
public void ArtifactsDirectory_Permissions ( )
1135
1232
{
@@ -1602,6 +1699,7 @@ public void Api()
1602
1699
<PropertyGroup>
1603
1700
<IncludeProjectNameInArtifactsPaths>false</IncludeProjectNameInArtifactsPaths>
1604
1701
<ArtifactsPath>/artifacts</ArtifactsPath>
1702
+ <PublishDir>artifacts/$(MSBuildProjectName)</PublishDir>
1605
1703
</PropertyGroup>
1606
1704
1607
1705
<!-- We need to explicitly import Sdk props/targets so we can override the targets below. -->
@@ -1676,6 +1774,7 @@ public void Api_Diagnostic_01()
1676
1774
<PropertyGroup>
1677
1775
<IncludeProjectNameInArtifactsPaths>false</IncludeProjectNameInArtifactsPaths>
1678
1776
<ArtifactsPath>/artifacts</ArtifactsPath>
1777
+ <PublishDir>artifacts/$(MSBuildProjectName)</PublishDir>
1679
1778
</PropertyGroup>
1680
1779
1681
1780
<!-- We need to explicitly import Sdk props/targets so we can override the targets below. -->
@@ -1743,6 +1842,7 @@ public void Api_Diagnostic_02()
1743
1842
<PropertyGroup>
1744
1843
<IncludeProjectNameInArtifactsPaths>false</IncludeProjectNameInArtifactsPaths>
1745
1844
<ArtifactsPath>/artifacts</ArtifactsPath>
1845
+ <PublishDir>artifacts/$(MSBuildProjectName)</PublishDir>
1746
1846
</PropertyGroup>
1747
1847
1748
1848
<!-- We need to explicitly import Sdk props/targets so we can override the targets below. -->
0 commit comments