StaticWebAssetsIntegrationTest.cs 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. using Microsoft.AspNetCore.StaticWebAssets.Tasks;
  4. namespace Microsoft.NET.Sdk.Razor.Tests
  5. {
  6. public class StaticWebAssetsIntegrationTest : AspNetSdkBaselineTest
  7. {
  8. public StaticWebAssetsIntegrationTest(ITestOutputHelper log) : base(log, GenerateBaselines) { }
  9. // Build Standalone project
  10. [Fact]
  11. public void Build_GeneratesJsonManifestAndCopiesItToOutputFolder()
  12. {
  13. var expectedManifest = LoadBuildManifest();
  14. var testAsset = "RazorComponentApp";
  15. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  16. var build = new BuildCommand(ProjectDirectory);
  17. build.WithWorkingDirectory(ProjectDirectory.TestRoot);
  18. build.Execute().Should().Pass();
  19. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  20. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  21. // GenerateStaticWebAssetsManifest should generate the manifest file.
  22. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  23. new FileInfo(path).Should().Exist();
  24. var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  25. AssertManifest(manifest, expectedManifest);
  26. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  27. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.runtime.json");
  28. new FileInfo(finalPath).Should().Exist();
  29. var manifest1 = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json")));
  30. AssertManifest(manifest1, expectedManifest);
  31. AssertBuildAssets(manifest1, outputPath, intermediateOutputPath);
  32. }
  33. [Fact]
  34. public void Build_DoesNotUpdateManifest_WhenHasNotChanged()
  35. {
  36. var testAsset = "RazorComponentApp";
  37. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  38. var build = new BuildCommand(ProjectDirectory);
  39. build.Execute().Should().Pass();
  40. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  41. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  42. // GenerateStaticWebAssetsManifest should generate the manifest file.
  43. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  44. var originalObjFile = new FileInfo(path);
  45. originalObjFile.Should().Exist();
  46. var objManifestContents = File.ReadAllText(Path.Combine(intermediateOutputPath, "staticwebassets.build.json"));
  47. AssertManifest(
  48. StaticWebAssetsManifest.FromJsonString(objManifestContents),
  49. LoadBuildManifest());
  50. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  51. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.runtime.json");
  52. var originalFile = new FileInfo(finalPath);
  53. originalFile.Should().Exist();
  54. var binManifestContents = File.ReadAllText(finalPath);
  55. var secondBuild = new BuildCommand(ProjectDirectory);
  56. secondBuild.Execute().Should().Pass();
  57. var secondPath = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  58. var secondObjFile = new FileInfo(secondPath);
  59. secondObjFile.Should().Exist();
  60. var secondObjManifest = File.ReadAllText(secondPath);
  61. secondObjManifest.Should().Be(objManifestContents);
  62. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  63. var secondFinalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.runtime.json");
  64. var secondFinalFile = new FileInfo(secondFinalPath);
  65. secondFinalFile.Should().Exist();
  66. var secondBinManifest = File.ReadAllText(secondFinalPath);
  67. secondBinManifest.Should().Be(binManifestContents);
  68. secondFinalFile.LastWriteTimeUtc.Should().Be(originalFile.LastWriteTimeUtc);
  69. }
  70. [Fact]
  71. public void Build_UpdatesManifest_WhenFilesChange()
  72. {
  73. var testAsset = "RazorComponentApp";
  74. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  75. var build = new BuildCommand(ProjectDirectory);
  76. build.Execute().Should().Pass();
  77. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  78. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  79. // GenerateStaticWebAssetsManifest should generate the manifest file.
  80. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  81. var originalObjFile = new FileInfo(path);
  82. originalObjFile.Should().Exist();
  83. var objManifestContents = File.ReadAllText(Path.Combine(intermediateOutputPath, "staticwebassets.build.json"));
  84. var firstManifest = StaticWebAssetsManifest.FromJsonString(objManifestContents);
  85. AssertManifest(firstManifest, LoadBuildManifest());
  86. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  87. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.runtime.json");
  88. var originalFile = new FileInfo(finalPath);
  89. originalFile.Should().Exist();
  90. var binManifestContents = File.ReadAllText(finalPath);
  91. AssertBuildAssets(
  92. firstManifest,
  93. outputPath,
  94. intermediateOutputPath);
  95. // Second build
  96. Directory.CreateDirectory(Path.Combine(ProjectDirectory.Path, "wwwroot"));
  97. File.WriteAllText(Path.Combine(ProjectDirectory.Path, "wwwroot", "index.html"), "some html");
  98. var secondBuild = new BuildCommand(ProjectDirectory);
  99. secondBuild.Execute().Should().Pass();
  100. var secondPath = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  101. var secondObjFile = new FileInfo(secondPath);
  102. secondObjFile.Should().Exist();
  103. var secondObjManifest = File.ReadAllText(secondPath);
  104. var secondManifest = StaticWebAssetsManifest.FromJsonString(secondObjManifest);
  105. AssertManifest(
  106. secondManifest,
  107. LoadBuildManifest("Updated"),
  108. "Updated");
  109. secondObjManifest.Should().NotBe(objManifestContents);
  110. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  111. var secondFinalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.runtime.json");
  112. var secondFinalFile = new FileInfo(secondFinalPath);
  113. secondFinalFile.Should().Exist();
  114. var secondBinManifest = File.ReadAllText(secondFinalPath);
  115. secondBinManifest.Should().NotBe(binManifestContents);
  116. secondObjFile.LastWriteTimeUtc.Should().NotBe(originalObjFile.LastWriteTimeUtc);
  117. secondFinalFile.LastWriteTimeUtc.Should().NotBe(originalFile.LastWriteTimeUtc);
  118. AssertBuildAssets(
  119. secondManifest,
  120. outputPath,
  121. intermediateOutputPath,
  122. "Updated");
  123. }
  124. // Project with references
  125. [Fact]
  126. public void BuildProjectWithReferences_GeneratesJsonManifestAndCopiesItToOutputFolder()
  127. {
  128. var testAsset = "RazorAppWithPackageAndP2PReference";
  129. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  130. var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  131. build.WithWorkingDirectory(ProjectDirectory.TestRoot);
  132. build.Execute().Should().Pass();
  133. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  134. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  135. // GenerateStaticWebAssetsManifest should generate the manifest file.
  136. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  137. new FileInfo(path).Should().Exist();
  138. var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  139. AssertManifest(
  140. manifest,
  141. LoadBuildManifest());
  142. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  143. var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  144. new FileInfo(finalPath).Should().Exist();
  145. AssertBuildAssets(
  146. manifest,
  147. outputPath,
  148. intermediateOutputPath);
  149. }
  150. [Fact]
  151. public void BuildProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibraries()
  152. {
  153. var testAsset = "RazorAppWithPackageAndP2PReference";
  154. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset)
  155. .WithProjectChanges((project, document) =>
  156. {
  157. if (Path.GetFileName(project) == "AnotherClassLib.csproj")
  158. {
  159. document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1");
  160. document.Descendants("FrameworkReference").Single().Remove();
  161. document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0"));
  162. }
  163. if (Path.GetFileName(project) == "ClassLibrary.csproj")
  164. {
  165. document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.0");
  166. document.Descendants("FrameworkReference").Single().Remove();
  167. document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0"));
  168. }
  169. });
  170. // We are deleting Views and Components because we are only interested in the static web assets behavior for this test
  171. // and this makes it easier to validate the test.
  172. Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "AnotherClassLib", "Views"), recursive: true);
  173. Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "ClassLibrary", "Views"), recursive: true);
  174. Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "ClassLibrary", "Components"), recursive: true);
  175. var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  176. build.WithWorkingDirectory(ProjectDirectory.TestRoot);
  177. build.Execute("/bl").Should().Pass();
  178. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  179. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  180. // GenerateStaticWebAssetsManifest should generate the manifest file.
  181. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  182. new FileInfo(path).Should().Exist();
  183. var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json")));
  184. AssertManifest(
  185. manifest,
  186. LoadBuildManifest());
  187. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  188. var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  189. new FileInfo(finalPath).Should().Exist();
  190. AssertBuildAssets(
  191. manifest,
  192. outputPath,
  193. intermediateOutputPath);
  194. }
  195. [Fact]
  196. public void PublishProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibraries()
  197. {
  198. var testAsset = "RazorAppWithPackageAndP2PReference";
  199. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset)
  200. .WithProjectChanges((project, document) =>
  201. {
  202. if (Path.GetFileName(project) == "AnotherClassLib.csproj")
  203. {
  204. document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1");
  205. document.Descendants("FrameworkReference").Single().Remove();
  206. document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0"));
  207. }
  208. if (Path.GetFileName(project) == "ClassLibrary.csproj")
  209. {
  210. document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.0");
  211. document.Descendants("FrameworkReference").Single().Remove();
  212. document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0"));
  213. }
  214. });
  215. // We are deleting Views and Components because we are only interested in the static web assets behavior for this test
  216. // and this makes it easier to validate the test.
  217. Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "AnotherClassLib", "Views"), recursive: true);
  218. Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "ClassLibrary", "Views"), recursive: true);
  219. Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "ClassLibrary", "Components"), recursive: true);
  220. var restore = new RestoreCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference"));
  221. restore.Execute().Should().Pass();
  222. var publish = new PublishCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  223. publish.WithWorkingDirectory(ProjectDirectory.Path);
  224. publish.Execute().Should().Pass();
  225. var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  226. var publishPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  227. // GenerateStaticWebAssetsManifest should generate the manifest file.
  228. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  229. new FileInfo(path).Should().Exist();
  230. AssertManifest(
  231. StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
  232. LoadBuildManifest());
  233. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  234. var finalPath = Path.Combine(publishPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  235. new FileInfo(finalPath).Should().NotExist();
  236. // GenerateStaticWebAssetsPublishManifest should generate the publish manifest file.
  237. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  238. new FileInfo(path).Should().Exist();
  239. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  240. AssertManifest(
  241. publishManifest,
  242. LoadPublishManifest());
  243. AssertPublishAssets(
  244. publishManifest,
  245. publishPath,
  246. intermediateOutputPath);
  247. }
  248. // Build no dependencies
  249. [Fact]
  250. public void BuildProjectWithReferences_NoDependencies_GeneratesJsonManifestAndCopiesItToOutputFolder()
  251. {
  252. var testAsset = "RazorAppWithPackageAndP2PReference";
  253. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  254. var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  255. build.Execute().Should().Pass();
  256. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  257. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  258. // GenerateStaticWebAssetsManifest should generate the manifest file.
  259. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  260. new FileInfo(path).Should().Exist();
  261. AssertManifest(
  262. StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
  263. LoadBuildManifest());
  264. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  265. var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  266. new FileInfo(finalPath).Should().Exist();
  267. var manifestContents = File.ReadAllText(finalPath);
  268. var initialManifest = StaticWebAssetsManifest.FromJsonString(File.ReadAllText(path));
  269. AssertManifest(
  270. initialManifest,
  271. LoadBuildManifest());
  272. // Second build
  273. var secondBuild = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  274. secondBuild.Execute("/p:BuildProjectReferences=false").Should().Pass();
  275. // GenerateStaticWebAssetsManifest should generate the manifest file.
  276. new FileInfo(path).Should().Exist();
  277. var manifestNoDeps = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  278. AssertManifest(
  279. manifestNoDeps,
  280. LoadBuildManifest("NoDependencies"),
  281. "NoDependencies");
  282. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  283. new FileInfo(finalPath).Should().Exist();
  284. var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json")));
  285. AssertManifest(
  286. manifest,
  287. LoadBuildManifest("NoDependencies"),
  288. "NoDependencies");
  289. AssertBuildAssets(
  290. manifest,
  291. outputPath,
  292. intermediateOutputPath,
  293. "NoDependencies");
  294. // Check that the two manifests are the same
  295. manifestContents.Should().Be(File.ReadAllText(finalPath));
  296. }
  297. // Rebuild
  298. [Fact]
  299. public void Rebuild_RegeneratesJsonManifestAndCopiesItToOutputFolder()
  300. {
  301. var testAsset = "RazorComponentApp";
  302. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  303. var build = new BuildCommand(ProjectDirectory);
  304. build.Execute().Should().Pass();
  305. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  306. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  307. // GenerateStaticWebAssetsManifest should generate the manifest file.
  308. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  309. var originalObjFile = new FileInfo(path);
  310. originalObjFile.Should().Exist();
  311. var objManifestContents = File.ReadAllText(Path.Combine(intermediateOutputPath, "staticwebassets.build.json"));
  312. AssertManifest(StaticWebAssetsManifest.FromJsonString(objManifestContents), LoadBuildManifest());
  313. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  314. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.runtime.json");
  315. var originalFile = new FileInfo(finalPath);
  316. originalFile.Should().Exist();
  317. var binManifestContents = File.ReadAllText(finalPath);
  318. // rebuild build
  319. var rebuild = new RebuildCommand(Log, ProjectDirectory.Path);
  320. rebuild.Execute().Should().Pass();
  321. var secondPath = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  322. var secondObjFile = new FileInfo(secondPath);
  323. secondObjFile.Should().Exist();
  324. var secondObjManifestContents = File.ReadAllText(secondPath);
  325. var secondManifest = StaticWebAssetsManifest.FromJsonString(secondObjManifestContents);
  326. AssertManifest(
  327. secondManifest,
  328. LoadBuildManifest("Rebuild"),
  329. "Rebuild");
  330. // This is no longer true because the manifests include the timestamp for the last modified
  331. // time of the file, etc.
  332. //secondObjManifestContents.Should().Be(objManifestContents);
  333. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  334. var secondFinalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.runtime.json");
  335. var secondFinalFile = new FileInfo(secondFinalPath);
  336. secondFinalFile.Should().Exist();
  337. var secondBinManifest = File.ReadAllText(secondFinalPath);
  338. secondBinManifest.Should().Be(binManifestContents);
  339. secondObjFile.LastWriteTimeUtc.Should().NotBe(originalObjFile.LastWriteTimeUtc);
  340. secondFinalFile.LastWriteTimeUtc.Should().NotBe(originalFile.LastWriteTimeUtc);
  341. AssertBuildAssets(
  342. secondManifest,
  343. outputPath,
  344. intermediateOutputPath,
  345. "Rebuild");
  346. }
  347. // Publish
  348. [Fact]
  349. public void Publish_GeneratesPublishJsonManifestAndCopiesPublishAssets()
  350. {
  351. var testAsset = "RazorComponentApp";
  352. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  353. var publish = new PublishCommand(ProjectDirectory);
  354. publish.Execute().Should().Pass();
  355. var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  356. var publishPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  357. // GenerateStaticWebAssetsManifest should generate the build manifest file.
  358. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  359. new FileInfo(path).Should().Exist();
  360. var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  361. AssertManifest(manifest, LoadBuildManifest());
  362. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  363. var finalPath = Path.Combine(publishPath, "ComponentApp.staticwebassets.runtime.json");
  364. new FileInfo(finalPath).Should().NotExist();
  365. // GenerateStaticWebAssetsManifest should generate the publish manifest file.
  366. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  367. new FileInfo(path).Should().Exist();
  368. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  369. AssertManifest(publishManifest, LoadPublishManifest());
  370. AssertPublishAssets(
  371. publishManifest,
  372. publishPath,
  373. intermediateOutputPath);
  374. }
  375. [Fact]
  376. public void Publish_PublishSingleFile_GeneratesPublishJsonManifestAndCopiesPublishAssets()
  377. {
  378. var expectedManifest = LoadBuildManifest();
  379. var testAsset = "RazorComponentApp";
  380. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  381. var publish = new PublishCommand(ProjectDirectory);
  382. publish.Execute("/p:PublishSingleFile=true", $"/p:RuntimeIdentifier={RuntimeInformation.RuntimeIdentifier}").Should().Pass();
  383. var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug", RuntimeInformation.RuntimeIdentifier).ToString();
  384. var publishPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  385. // GenerateStaticWebAssetsManifest should generate the build manifest file.
  386. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  387. new FileInfo(path).Should().Exist();
  388. var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  389. AssertManifest(manifest, expectedManifest, runtimeIdentifier: RuntimeInformation.RuntimeIdentifier);
  390. // GenerateStaticWebAssetsManifest should not copy the file to the output folder.
  391. var finalPath = Path.Combine(publishPath, "ComponentApp.staticwebassets.runtime.json");
  392. new FileInfo(finalPath).Should().NotExist();
  393. // GenerateStaticWebAssetsManifest should generate the publish manifest file.
  394. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  395. new FileInfo(path).Should().Exist();
  396. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  397. AssertManifest(
  398. publishManifest,
  399. LoadPublishManifest(),
  400. runtimeIdentifier: RuntimeInformation.RuntimeIdentifier);
  401. AssertPublishAssets(
  402. publishManifest,
  403. publishPath,
  404. intermediateOutputPath);
  405. }
  406. [Fact]
  407. public void Publish_NoBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets()
  408. {
  409. var expectedManifest = LoadBuildManifest();
  410. var testAsset = "RazorComponentApp";
  411. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  412. var build = new BuildCommand(ProjectDirectory);
  413. build.Execute().Should().Pass();
  414. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  415. var publishPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  416. // GenerateStaticWebAssetsManifest should generate the manifest file.
  417. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  418. var objManifestFile = new FileInfo(path);
  419. objManifestFile.Should().Exist();
  420. var objManifestFileTimeStamp = objManifestFile.LastWriteTimeUtc;
  421. var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  422. AssertManifest(manifest, expectedManifest);
  423. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  424. var finalPath = Path.Combine(publishPath, "ComponentApp.staticwebassets.runtime.json");
  425. var binManifestFile = new FileInfo(finalPath);
  426. binManifestFile.Should().Exist();
  427. var binManifestTimeStamp = binManifestFile.LastWriteTimeUtc;
  428. var finalManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json")));
  429. AssertManifest(finalManifest, expectedManifest);
  430. // Publish no build
  431. var publish = new PublishCommand(ProjectDirectory);
  432. publish.Execute("/p:NoBuild=true").Should().Pass();
  433. var secondObjTimeStamp = new FileInfo(path).LastWriteTimeUtc;
  434. secondObjTimeStamp.Should().Be(objManifestFileTimeStamp);
  435. var seconbObjManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  436. AssertManifest(seconbObjManifest, expectedManifest);
  437. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  438. var seconBinManifestPath = Path.Combine(publishPath, "ComponentApp.staticwebassets.runtime.json");
  439. var secondBinManifestFile = new FileInfo(seconBinManifestPath);
  440. secondBinManifestFile.Should().Exist();
  441. secondBinManifestFile.LastWriteTimeUtc.Should().Be(binManifestTimeStamp);
  442. var secondBinManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json")));
  443. AssertManifest(secondBinManifest, expectedManifest);
  444. // GenerateStaticWebAssetsManifest should generate the publish manifest file.
  445. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  446. new FileInfo(path).Should().Exist();
  447. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  448. AssertManifest(
  449. publishManifest,
  450. LoadPublishManifest());
  451. AssertPublishAssets(
  452. publishManifest,
  453. publishPath,
  454. intermediateOutputPath);
  455. }
  456. [Fact]
  457. public void Build_DeployOnBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets()
  458. {
  459. var expectedManifest = LoadBuildManifest();
  460. var testAsset = "RazorComponentApp";
  461. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  462. var build = new BuildCommand(ProjectDirectory);
  463. build.Execute("/p:DeployOnBuild=true").Should().Pass();
  464. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  465. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  466. // GenerateStaticWebAssetsManifest should generate the build manifest file.
  467. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  468. new FileInfo(path).Should().Exist();
  469. var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  470. AssertManifest(manifest, LoadBuildManifest());
  471. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  472. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.runtime.json");
  473. new FileInfo(finalPath).Should().Exist();
  474. // GenerateStaticWebAssetsManifest should generate the publish manifest file.
  475. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  476. new FileInfo(path).Should().Exist();
  477. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  478. AssertManifest(publishManifest, LoadPublishManifest());
  479. AssertPublishAssets(
  480. publishManifest,
  481. Path.Combine(outputPath, "publish"),
  482. intermediateOutputPath);
  483. }
  484. [Fact]
  485. public void PublishProjectWithReferences_GeneratesPublishJsonManifestAndCopiesPublishAssets()
  486. {
  487. var testAsset = "RazorAppWithPackageAndP2PReference";
  488. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  489. var restore = new RestoreCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference"));
  490. restore.Execute().Should().Pass();
  491. var publish = new PublishCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  492. publish.WithWorkingDirectory(ProjectDirectory.Path);
  493. publish.Execute().Should().Pass();
  494. var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  495. var publishPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  496. // GenerateStaticWebAssetsManifest should generate the manifest file.
  497. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  498. new FileInfo(path).Should().Exist();
  499. AssertManifest(
  500. StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
  501. LoadBuildManifest());
  502. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  503. var finalPath = Path.Combine(publishPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  504. new FileInfo(finalPath).Should().NotExist();
  505. // GenerateStaticWebAssetsPublishManifest should generate the publish manifest file.
  506. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  507. new FileInfo(path).Should().Exist();
  508. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  509. AssertManifest(
  510. publishManifest,
  511. LoadPublishManifest());
  512. AssertPublishAssets(
  513. publishManifest,
  514. publishPath,
  515. intermediateOutputPath);
  516. }
  517. [Fact]
  518. public void PublishProjectWithReferences_PublishSingleFile_GeneratesPublishJsonManifestAndCopiesPublishAssets()
  519. {
  520. var testAsset = "RazorAppWithPackageAndP2PReference";
  521. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  522. var publish = new PublishCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  523. publish.Execute("/p:PublishSingleFile=true", $"/p:RuntimeIdentifier={RuntimeInformation.RuntimeIdentifier}").Should().Pass();
  524. var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug", RuntimeInformation.RuntimeIdentifier).ToString();
  525. var publishPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  526. // GenerateStaticWebAssetsManifest should generate the manifest file.
  527. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  528. new FileInfo(path).Should().Exist();
  529. AssertManifest(
  530. StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
  531. LoadBuildManifest(),
  532. runtimeIdentifier: RuntimeInformation.RuntimeIdentifier);
  533. // GenerateStaticWebAssetsManifest should not copy the file to the output folder.
  534. var finalPath = Path.Combine(publishPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  535. new FileInfo(finalPath).Should().NotExist();
  536. // GenerateStaticWebAssetsPublishManifest should generate the publish manifest file.
  537. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  538. new FileInfo(path).Should().Exist();
  539. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  540. AssertManifest(publishManifest, LoadPublishManifest(), runtimeIdentifier: RuntimeInformation.RuntimeIdentifier);
  541. AssertPublishAssets(
  542. publishManifest,
  543. publishPath,
  544. intermediateOutputPath);
  545. }
  546. [Fact]
  547. public void PublishProjectWithReferences_NoBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets()
  548. {
  549. var testAsset = "RazorAppWithPackageAndP2PReference";
  550. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  551. var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  552. build.WithWorkingDirectory(ProjectDirectory.TestRoot);
  553. build.Execute().Should().Pass();
  554. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  555. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  556. // GenerateStaticWebAssetsManifest should generate the manifest file.
  557. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  558. var objManifestFile = new FileInfo(path);
  559. objManifestFile.Should().Exist();
  560. var objManifestFileTimeStamp = objManifestFile.LastWriteTimeUtc;
  561. AssertManifest(
  562. StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
  563. LoadBuildManifest());
  564. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  565. var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  566. var binManifestFile = new FileInfo(finalPath);
  567. binManifestFile.Should().Exist();
  568. var binManifestTimeStamp = binManifestFile.LastWriteTimeUtc;
  569. AssertManifest(
  570. StaticWebAssetsManifest.FromJsonString(File.ReadAllText(path)),
  571. LoadBuildManifest());
  572. // Publish no build
  573. var publish = new PublishCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference"));
  574. var publishResult = publish.Execute("/p:NoBuild=true", "/p:ErrorOnDuplicatePublishOutputFiles=false");
  575. var publishPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  576. publishResult.Should().Pass();
  577. new FileInfo(path).LastWriteTimeUtc.Should().Be(objManifestFileTimeStamp);
  578. var seconbObjManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  579. AssertManifest(seconbObjManifest, LoadBuildManifest());
  580. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  581. var seconBinManifestPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  582. var secondBinManifestFile = new FileInfo(seconBinManifestPath);
  583. secondBinManifestFile.Should().Exist();
  584. secondBinManifestFile.LastWriteTimeUtc.Should().Be(binManifestTimeStamp);
  585. // GenerateStaticWebAssetsManifest should generate the publish manifest file.
  586. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  587. new FileInfo(path).Should().Exist();
  588. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  589. AssertManifest(publishManifest, LoadPublishManifest());
  590. AssertPublishAssets(
  591. publishManifest,
  592. publishPath,
  593. intermediateOutputPath);
  594. }
  595. [Fact]
  596. public void PublishProjectWithReferences_AppendTargetFrameworkToOutputPathFalse_GeneratesPublishJsonManifestAndCopiesPublishAssets()
  597. {
  598. var testAsset = "RazorAppWithPackageAndP2PReference";
  599. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  600. var restore = new RestoreCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference"));
  601. restore.Execute().Should().Pass();
  602. var publish = new PublishCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  603. publish.WithWorkingDirectory(ProjectDirectory.Path);
  604. publish.Execute("/p:AppendTargetFrameworkToOutputPath=false").Should().Pass();
  605. // Hard code output paths here to account for AppendTargetFrameworkToOutputPath=false
  606. var intermediateOutputPath = Path.Combine(ProjectDirectory.Path, "AppWithPackageAndP2PReference", "obj", "Debug");
  607. var publishPath = Path.Combine(ProjectDirectory.Path, "AppWithPackageAndP2PReference", "bin", "Debug", "publish");
  608. // GenerateStaticWebAssetsManifest should generate the manifest file.
  609. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  610. new FileInfo(path).Should().Exist();
  611. AssertManifest(
  612. StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
  613. LoadBuildManifest());
  614. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  615. var finalPath = Path.Combine(publishPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  616. new FileInfo(finalPath).Should().NotExist();
  617. // GenerateStaticWebAssetsPublishManifest should generate the publish manifest file.
  618. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  619. new FileInfo(path).Should().Exist();
  620. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  621. AssertManifest(
  622. publishManifest,
  623. LoadPublishManifest());
  624. AssertPublishAssets(
  625. publishManifest,
  626. publishPath,
  627. intermediateOutputPath);
  628. }
  629. [Fact]
  630. public void BuildProjectWithReferences_DeployOnBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets()
  631. {
  632. var testAsset = "RazorAppWithPackageAndP2PReference";
  633. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  634. var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
  635. build.Execute("/p:DeployOnBuild=true").Should().Pass();
  636. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  637. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  638. // GenerateStaticWebAssetsManifest should generate the manifest file.
  639. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  640. new FileInfo(path).Should().Exist();
  641. AssertManifest(
  642. StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
  643. LoadBuildManifest());
  644. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  645. var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.runtime.json");
  646. new FileInfo(finalPath).Should().Exist();
  647. // GenerateStaticWebAssetsManifest should generate the publish manifest file.
  648. var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
  649. new FileInfo(path).Should().Exist();
  650. var publishManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath));
  651. AssertManifest(publishManifest, LoadPublishManifest());
  652. AssertPublishAssets(
  653. publishManifest,
  654. Path.Combine(outputPath, "publish"),
  655. intermediateOutputPath);
  656. }
  657. // Pack
  658. // Clean
  659. [Fact]
  660. public void Clean_RemovesManifestFrom_BuildAndIntermediateOutput()
  661. {
  662. var expectedManifest = LoadBuildManifest();
  663. var testAsset = "RazorComponentApp";
  664. ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
  665. var build = new BuildCommand(ProjectDirectory);
  666. build.Execute().Should().Pass();
  667. var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  668. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  669. // GenerateStaticWebAssetsManifest should generate the manifest file.
  670. var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
  671. new FileInfo(path).Should().Exist();
  672. var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
  673. AssertManifest(manifest, expectedManifest);
  674. // GenerateStaticWebAssetsManifest should copy the file to the output folder.
  675. var finalPath = Path.Combine(outputPath, "ComponentApp.staticwebassets.runtime.json");
  676. new FileInfo(finalPath).Should().Exist();
  677. var finalManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(Path.Combine(intermediateOutputPath, "staticwebassets.build.json")));
  678. AssertManifest(finalManifest, expectedManifest);
  679. var clean = new CleanCommand(Log, ProjectDirectory.Path);
  680. clean.Execute().Should().Pass();
  681. // Obj folder manifest does not exist
  682. new FileInfo(path).Should().NotExist();
  683. // Bin folder manifest does not exist
  684. new FileInfo(finalPath).Should().NotExist();
  685. }
  686. [Fact]
  687. public void Build_Fails_WhenConflictingAssetsFoundBetweenAStaticWebAssetAndAFileInTheWebRootFolder()
  688. {
  689. var testAsset = "RazorAppWithPackageAndP2PReference";
  690. var projectDirectory = CreateAspNetSdkTestAsset(testAsset);
  691. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "AppWithPackageAndP2PReference", "wwwroot", "_content", "ClassLibrary", "js"));
  692. File.WriteAllText(Path.Combine(projectDirectory.Path, "AppWithPackageAndP2PReference", "wwwroot", "_content", "ClassLibrary", "js", "project-transitive-dep.js"), "console.log('transitive-dep');");
  693. var build = new BuildCommand(projectDirectory, "AppWithPackageAndP2PReference");
  694. build.Execute().Should().Fail();
  695. }
  696. [Fact]
  697. public void Pack_FailsWhenStaticWebAssetsHaveConflictingPaths()
  698. {
  699. var testAsset = "PackageLibraryDirectDependency";
  700. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages")
  701. .WithProjectChanges(project =>
  702. {
  703. var ns = project.Root.Name.Namespace;
  704. var itemGroup = new XElement(ns + "ItemGroup");
  705. var element = new XElement("StaticWebAsset", new XAttribute("Include", @"bundle\js\pkg-direct-dep.js"));
  706. element.Add(new XElement("SourceType"));
  707. element.Add(new XElement("SourceId", "PackageLibraryDirectDependency"));
  708. element.Add(new XElement("ContentRoot", "$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)\\bundle\\'))"));
  709. element.Add(new XElement("BasePath", "_content/PackageLibraryDirectDependency"));
  710. element.Add(new XElement("RelativePath", "js/pkg-direct-dep.js"));
  711. itemGroup.Add(element);
  712. project.Root.Add(itemGroup);
  713. });
  714. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "bundle", "js"));
  715. File.WriteAllText(Path.Combine(projectDirectory.Path, "bundle", "js", "pkg-direct-dep.js"), "console.log('bundle');");
  716. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path, "PackageLibraryDirectDependency");
  717. pack.Execute().Should().Fail();
  718. }
  719. // If you modify this test, make sure you also modify the test below this one to assert that things are not included as content.
  720. [Fact]
  721. public void Pack_IncludesStaticWebAssets()
  722. {
  723. var testAsset = "PackageLibraryDirectDependency";
  724. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  725. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  726. pack.WithWorkingDirectory(projectDirectory.Path);
  727. var result = pack.Execute("/bl");
  728. result.Should().Pass();
  729. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  730. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  731. result.Should().NuPkgContain(
  732. Path.Combine(pack.GetPackageDirectory().FullName, "PackageLibraryDirectDependency.1.0.0.nupkg"),
  733. filePaths: new[]
  734. {
  735. Path.Combine("staticwebassets", "js", "pkg-direct-dep.js"),
  736. Path.Combine("staticwebassets", "css", "site.css"),
  737. Path.Combine("staticwebassets", "PackageLibraryDirectDependency.bundle.scp.css"),
  738. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  739. Path.Combine("build", "PackageLibraryDirectDependency.props"),
  740. Path.Combine("buildMultiTargeting", "PackageLibraryDirectDependency.props"),
  741. Path.Combine("buildTransitive", "PackageLibraryDirectDependency.props")
  742. });
  743. }
  744. [Fact]
  745. public void Pack_NoAssets_DoesNothing()
  746. {
  747. var testAsset = "PackageLibraryNoStaticAssets";
  748. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  749. var pack = new MSBuildCommand(projectDirectory, "Pack");
  750. pack.WithWorkingDirectory(projectDirectory.Path);
  751. var result = pack.Execute();
  752. result.Should().Pass();
  753. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  754. new FileInfo(Path.Combine(outputPath, "PackageLibraryNoStaticAssets.dll")).Should().Exist();
  755. result.Should().NuPkgDoesNotContain(
  756. Path.Combine(pack.GetPackageDirectory().FullName, "PackageLibraryNoStaticAssets.1.0.0.nupkg"),
  757. filePaths: new[]
  758. {
  759. Path.Combine("staticwebassets"),
  760. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  761. Path.Combine("build", "PackageLibraryNoStaticAssets.props"),
  762. Path.Combine("buildMultiTargeting", "PackageLibraryNoStaticAssets.props"),
  763. Path.Combine("buildTransitive", "PackageLibraryNoStaticAssets.props")
  764. });
  765. }
  766. [Fact]
  767. public void Pack_NoAssets_Multitargeting_DoesNothing()
  768. {
  769. var testAsset = "PackageLibraryNoStaticAssets";
  770. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  771. projectDirectory.WithProjectChanges(project =>
  772. {
  773. var tfm = project.Root.Descendants("TargetFramework").Single();
  774. tfm.Name = "TargetFrameworks";
  775. tfm.Value = "net6.0;" + DefaultTfm;
  776. });
  777. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  778. pack.WithWorkingDirectory(projectDirectory.Path);
  779. var result = pack.Execute();
  780. result.Should().Pass();
  781. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  782. new FileInfo(Path.Combine(outputPath, "PackageLibraryNoStaticAssets.dll")).Should().Exist();
  783. result.Should().NuPkgDoesNotContain(
  784. Path.Combine(projectDirectory.Path, "bin", "Debug", "PackageLibraryNoStaticAssets.1.0.0.nupkg"),
  785. filePaths: new[]
  786. {
  787. Path.Combine("staticwebassets"),
  788. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  789. Path.Combine("build", "PackageLibraryNoStaticAssets.props"),
  790. Path.Combine("buildMultiTargeting", "PackageLibraryNoStaticAssets.props"),
  791. Path.Combine("buildTransitive", "PackageLibraryNoStaticAssets.props")
  792. });
  793. }
  794. [Fact]
  795. public void Pack_Incremental_IncludesStaticWebAssets()
  796. {
  797. var testAsset = "PackageLibraryDirectDependency";
  798. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  799. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  800. pack.WithWorkingDirectory(projectDirectory.Path);
  801. var result = pack.Execute();
  802. result.Should().Pass();
  803. var pack2 = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  804. pack2.WithWorkingDirectory(projectDirectory.Path);
  805. var result2 = pack2.Execute();
  806. result2.Should().Pass();
  807. var outputPath = pack2.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  808. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  809. result2.Should().NuPkgContain(
  810. Path.Combine(pack2.GetPackageDirectory().FullName, "PackageLibraryDirectDependency.1.0.0.nupkg"),
  811. filePaths: new[]
  812. {
  813. Path.Combine("staticwebassets", "js", "pkg-direct-dep.js"),
  814. Path.Combine("staticwebassets", "css", "site.css"),
  815. Path.Combine("staticwebassets", "PackageLibraryDirectDependency.bundle.scp.css"),
  816. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  817. Path.Combine("build", "PackageLibraryDirectDependency.props"),
  818. Path.Combine("buildMultiTargeting", "PackageLibraryDirectDependency.props"),
  819. Path.Combine("buildTransitive", "PackageLibraryDirectDependency.props")
  820. });
  821. }
  822. [Fact]
  823. public void Pack_StaticWebAssets_WithoutFileExtension_AreCorrectlyPacked()
  824. {
  825. var testAsset = "PackageLibraryDirectDependency";
  826. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  827. File.WriteAllText(Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "wwwroot", "LICENSE"), "license file contents");
  828. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  829. pack.WithWorkingDirectory(projectDirectory.Path);
  830. var result = pack.Execute();
  831. result.Should().Pass();
  832. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  833. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  834. result.Should().NuPkgContain(
  835. Path.Combine(pack.GetPackageDirectory().FullName, "PackageLibraryDirectDependency.1.0.0.nupkg"),
  836. filePaths: new[]
  837. {
  838. Path.Combine("staticwebassets", "js", "pkg-direct-dep.js"),
  839. Path.Combine("staticwebassets", "css", "site.css"),
  840. Path.Combine("staticwebassets", "LICENSE"),
  841. Path.Combine("staticwebassets", "PackageLibraryDirectDependency.bundle.scp.css"),
  842. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  843. Path.Combine("build", "PackageLibraryDirectDependency.props"),
  844. Path.Combine("buildMultiTargeting", "PackageLibraryDirectDependency.props"),
  845. Path.Combine("buildTransitive", "PackageLibraryDirectDependency.props")
  846. });
  847. }
  848. [Fact]
  849. public void Build_StaticWebAssets_GeneratePackageOnBuild_PacksStaticWebAssets()
  850. {
  851. var testAsset = "PackageLibraryDirectDependency";
  852. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  853. File.WriteAllText(Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "wwwroot", "LICENSE"), "license file contents");
  854. var buildCommand = new BuildCommand(projectDirectory, "PackageLibraryDirectDependency");
  855. buildCommand.WithWorkingDirectory(projectDirectory.Path);
  856. var result = buildCommand.Execute("/p:GeneratePackageOnBuild=true");
  857. result.Should().Pass();
  858. var outputPath = buildCommand.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  859. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  860. result.Should().NuPkgContain(
  861. Path.Combine(buildCommand.GetPackageDirectory().FullName, "PackageLibraryDirectDependency.1.0.0.nupkg"),
  862. filePaths: new[]
  863. {
  864. Path.Combine("staticwebassets", "js", "pkg-direct-dep.js"),
  865. Path.Combine("staticwebassets", "css", "site.css"),
  866. Path.Combine("staticwebassets", "PackageLibraryDirectDependency.bundle.scp.css"),
  867. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  868. Path.Combine("build", "PackageLibraryDirectDependency.props"),
  869. Path.Combine("buildMultiTargeting", "PackageLibraryDirectDependency.props"),
  870. Path.Combine("buildTransitive", "PackageLibraryDirectDependency.props")
  871. });
  872. }
  873. [Fact]
  874. public void Build_StaticWebAssets_GeneratePackageOnBuild_DoesNotIncludeAssetsAsContent()
  875. {
  876. var testAsset = "PackageLibraryDirectDependency";
  877. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  878. File.WriteAllText(Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "wwwroot", "LICENSE"), "license file contents");
  879. var buildCommand = new BuildCommand(projectDirectory, "PackageLibraryDirectDependency");
  880. buildCommand.WithWorkingDirectory(projectDirectory.Path);
  881. var result = buildCommand.Execute("/p:GeneratePackageOnBuild=true");
  882. result.Should().Pass();
  883. var outputPath = buildCommand.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  884. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  885. result.Should().NuPkgDoesNotContain(
  886. Path.Combine(buildCommand.GetPackageDirectory().FullName, "PackageLibraryDirectDependency.1.0.0.nupkg"),
  887. filePaths: new[]
  888. {
  889. Path.Combine("content", "js", "pkg-direct-dep.js"),
  890. Path.Combine("content", "css", "site.css"),
  891. Path.Combine("content", "PackageLibraryDirectDependency.bundle.scp.css"),
  892. Path.Combine("contentFiles", "js", "pkg-direct-dep.js"),
  893. Path.Combine("contentFiles", "css", "site.css"),
  894. Path.Combine("contentFiles", "PackageLibraryDirectDependency.bundle.scp.css"),
  895. });
  896. }
  897. [Fact]
  898. public void Pack_MultipleTargetFrameworks_Works()
  899. {
  900. var testAsset = "PackageLibraryDirectDependency";
  901. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  902. projectDirectory.WithProjectChanges((project, document) =>
  903. {
  904. var tfm = document.Descendants("TargetFramework").Single();
  905. tfm.Name = "TargetFrameworks";
  906. tfm.FirstNode.ReplaceWith(tfm.FirstNode.ToString() + ";netstandard2.1");
  907. document.Descendants("AddRazorSupportForMvc").SingleOrDefault()?.Remove();
  908. document.Descendants("FrameworkReference").SingleOrDefault()?.Remove();
  909. });
  910. Directory.Delete(Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "Components"), recursive: true);
  911. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  912. pack.WithWorkingDirectory(projectDirectory.Path);
  913. var result = pack.Execute("/bl");
  914. result.Should().Pass();
  915. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  916. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  917. result.Should().NuPkgContain(
  918. Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "bin", "Debug", "PackageLibraryDirectDependency.1.0.0.nupkg"),
  919. filePaths: new[]
  920. {
  921. Path.Combine("staticwebassets", "js", "pkg-direct-dep.js"),
  922. Path.Combine("staticwebassets", "css", "site.css"),
  923. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  924. Path.Combine("build", "PackageLibraryDirectDependency.props"),
  925. Path.Combine("buildMultiTargeting", "PackageLibraryDirectDependency.props"),
  926. Path.Combine("buildTransitive", "PackageLibraryDirectDependency.props")
  927. });
  928. }
  929. [Fact]
  930. public void Pack_MultipleTargetFrameworks_NoBuild_IncludesStaticWebAssets()
  931. {
  932. var testAsset = "PackageLibraryDirectDependency";
  933. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  934. projectDirectory.WithProjectChanges((project, document) =>
  935. {
  936. var tfm = document.Descendants("TargetFramework").Single();
  937. tfm.Name = "TargetFrameworks";
  938. tfm.FirstNode.ReplaceWith(tfm.FirstNode.ToString() + ";netstandard2.1");
  939. document.Descendants("AddRazorSupportForMvc").SingleOrDefault()?.Remove();
  940. document.Descendants("FrameworkReference").SingleOrDefault()?.Remove();
  941. });
  942. Directory.Delete(Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "Components"), recursive: true);
  943. var build = new BuildCommand(projectDirectory, "PackageLibraryDirectDependency");
  944. build.WithWorkingDirectory(projectDirectory.Path);
  945. var buildResult = build.Execute();
  946. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  947. pack.WithWorkingDirectory(projectDirectory.Path);
  948. var result = pack.Execute("/p:NoBuild=true");
  949. result.Should().Pass();
  950. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  951. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  952. result.Should().NuPkgContain(
  953. Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "bin", "Debug", "PackageLibraryDirectDependency.1.0.0.nupkg"),
  954. filePaths: new[]
  955. {
  956. Path.Combine("staticwebassets", "js", "pkg-direct-dep.js"),
  957. Path.Combine("staticwebassets", "css", "site.css"),
  958. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  959. Path.Combine("build", "PackageLibraryDirectDependency.props"),
  960. Path.Combine("buildMultiTargeting", "PackageLibraryDirectDependency.props"),
  961. Path.Combine("buildTransitive", "PackageLibraryDirectDependency.props")
  962. });
  963. }
  964. [Fact]
  965. public void Pack_MultipleTargetFrameworks_NoBuild_DoesNotIncludeAssetsAsContent()
  966. {
  967. var testAsset = "PackageLibraryDirectDependency";
  968. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  969. projectDirectory.WithProjectChanges((project, document) =>
  970. {
  971. var tfm = document.Descendants("TargetFramework").Single();
  972. tfm.Name = "TargetFrameworks";
  973. tfm.FirstNode.ReplaceWith(tfm.FirstNode.ToString() + ";netstandard2.1");
  974. document.Descendants("AddRazorSupportForMvc").SingleOrDefault()?.Remove();
  975. document.Descendants("FrameworkReference").SingleOrDefault()?.Remove();
  976. });
  977. Directory.Delete(Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "Components"), recursive: true);
  978. var build = new BuildCommand(Log, projectDirectory.Path, "PackageLibraryDirectDependency");
  979. build.WithWorkingDirectory(projectDirectory.Path);
  980. var buildResult = build.Execute();
  981. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  982. pack.WithWorkingDirectory(projectDirectory.Path);
  983. var result = pack.Execute("/p:NoBuild=true");
  984. result.Should().Pass();
  985. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  986. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  987. result.Should().NuPkgDoesNotContain(
  988. Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "bin", "Debug", "PackageLibraryDirectDependency.1.0.0.nupkg"),
  989. filePaths: new[]
  990. {
  991. Path.Combine("content", "wwwroot", "js", "pkg-direct-dep.js"),
  992. Path.Combine("content", "wwwroot", "css", "site.css"),
  993. Path.Combine("contentFiles", "wwwroot", "js", "pkg-direct-dep.js"),
  994. Path.Combine("contentFiles", "wwwroot", "css", "site.css"),
  995. });
  996. }
  997. [Fact]
  998. public void Pack_MultipleTargetFrameworks_GeneratePackageOnBuild_IncludesStaticWebAssets()
  999. {
  1000. var testAsset = "PackageLibraryDirectDependency";
  1001. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1002. projectDirectory.WithProjectChanges((project, document) =>
  1003. {
  1004. var tfm = document.Descendants("TargetFramework").Single();
  1005. tfm.Name = "TargetFrameworks";
  1006. tfm.FirstNode.ReplaceWith(tfm.FirstNode.ToString() + ";netstandard2.1");
  1007. document.Descendants("AddRazorSupportForMvc").SingleOrDefault()?.Remove();
  1008. document.Descendants("FrameworkReference").SingleOrDefault()?.Remove();
  1009. });
  1010. Directory.Delete(Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "Components"), recursive: true);
  1011. var build = new BuildCommand(projectDirectory, "PackageLibraryDirectDependency");
  1012. build.WithWorkingDirectory(projectDirectory.Path);
  1013. var result = build.Execute("/p:GeneratePackageOnBuild=true");
  1014. result.Should().Pass();
  1015. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  1016. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  1017. result.Should().NuPkgContain(
  1018. Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "bin", "Debug", "PackageLibraryDirectDependency.1.0.0.nupkg"),
  1019. filePaths: new[]
  1020. {
  1021. Path.Combine("staticwebassets", "js", "pkg-direct-dep.js"),
  1022. Path.Combine("staticwebassets", "css", "site.css"),
  1023. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  1024. Path.Combine("build", "PackageLibraryDirectDependency.props"),
  1025. Path.Combine("buildMultiTargeting", "PackageLibraryDirectDependency.props"),
  1026. Path.Combine("buildTransitive", "PackageLibraryDirectDependency.props")
  1027. });
  1028. }
  1029. [Fact]
  1030. public void Pack_MultipleTargetFrameworks_GeneratePackageOnBuild_DoesNotIncludeAssetsAsContent()
  1031. {
  1032. var testAsset = "PackageLibraryDirectDependency";
  1033. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1034. projectDirectory.WithProjectChanges((project, document) =>
  1035. {
  1036. var tfm = document.Descendants("TargetFramework").Single();
  1037. tfm.Name = "TargetFrameworks";
  1038. tfm.FirstNode.ReplaceWith(tfm.FirstNode.ToString() + ";netstandard2.1");
  1039. document.Descendants("AddRazorSupportForMvc").SingleOrDefault()?.Remove();
  1040. document.Descendants("FrameworkReference").SingleOrDefault()?.Remove();
  1041. });
  1042. Directory.Delete(Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "Components"), recursive: true);
  1043. var build = new BuildCommand(projectDirectory, "PackageLibraryDirectDependency");
  1044. build.WithWorkingDirectory(projectDirectory.Path);
  1045. var result = build.Execute("/p:GeneratePackageOnBuild=true");
  1046. result.Should().Pass();
  1047. var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  1048. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  1049. result.Should().NuPkgDoesNotContain(
  1050. Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "bin", "Debug", "PackageLibraryDirectDependency.1.0.0.nupkg"),
  1051. filePaths: new[]
  1052. {
  1053. Path.Combine("content", "wwwroot", "js", "pkg-direct-dep.js"),
  1054. Path.Combine("content", "wwwroot", "css", "site.css"),
  1055. Path.Combine("contentFiles", "wwwroot", "js", "pkg-direct-dep.js"),
  1056. Path.Combine("contentFiles", "wwwroot", "css", "site.css"),
  1057. });
  1058. }
  1059. [Fact]
  1060. public void Pack_BeforeNet60_MultipleTargetFrameworks_WithScopedCss_IncludesAssetsAndProjectBundle()
  1061. {
  1062. var testAsset = "PackageLibraryTransitiveDependency";
  1063. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1064. projectDirectory.WithProjectChanges(document =>
  1065. {
  1066. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1067. <PropertyGroup>
  1068. <TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
  1069. <RazorLangVersion>3.0</RazorLangVersion>
  1070. </PropertyGroup>
  1071. <ItemGroup>
  1072. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1073. <PackageReference Condition=""'$(TargetFramework)' == 'netstandard2.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""3.1.0"" />
  1074. </ItemGroup>
  1075. </Project>
  1076. ");
  1077. document.Root.ReplaceWith(parse.Root);
  1078. });
  1079. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1080. var componentText = @"<div class=""my-component"">
  1081. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1082. </div>";
  1083. // This mimics the structure of our default template project
  1084. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1085. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1086. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1087. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1088. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1089. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1090. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1091. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1092. pack.WithWorkingDirectory(projectDirectory.Path);
  1093. var result = pack.Execute("/bl");
  1094. result.Should().Pass();
  1095. var outputPath = pack.GetOutputDirectory("net5.0", "Debug").ToString();
  1096. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1097. var packagePath = Path.Combine(
  1098. projectDirectory.Path,
  1099. "bin",
  1100. "Debug",
  1101. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1102. result.Should().NuPkgContain(
  1103. packagePath,
  1104. filePaths: new[]
  1105. {
  1106. Path.Combine("staticwebassets", "exampleJsInterop.js"),
  1107. Path.Combine("staticwebassets", "background.png"),
  1108. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1109. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  1110. Path.Combine("build", "PackageLibraryTransitiveDependency.props"),
  1111. Path.Combine("buildMultiTargeting", "PackageLibraryTransitiveDependency.props"),
  1112. Path.Combine("buildTransitive", "PackageLibraryTransitiveDependency.props")
  1113. });
  1114. }
  1115. [Fact]
  1116. public void Pack_BeforeNet60_MultipleTargetFrameworks_WithScopedCss_DoesNotIncludeAssetsAsContent()
  1117. {
  1118. var testAsset = "PackageLibraryTransitiveDependency";
  1119. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1120. projectDirectory.WithProjectChanges(document =>
  1121. {
  1122. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1123. <PropertyGroup>
  1124. <TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
  1125. <RazorLangVersion>3.0</RazorLangVersion>
  1126. </PropertyGroup>
  1127. <ItemGroup>
  1128. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1129. <PackageReference Condition=""'$(TargetFramework)' == 'netstandard2.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""3.1.0"" />
  1130. </ItemGroup>
  1131. </Project>
  1132. ");
  1133. document.Root.ReplaceWith(parse.Root);
  1134. });
  1135. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1136. var componentText = @"<div class=""my-component"">
  1137. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1138. </div>";
  1139. // This mimics the structure of our default template project
  1140. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1141. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1142. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1143. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1144. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1145. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1146. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1147. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1148. pack.WithWorkingDirectory(projectDirectory.Path);
  1149. var result = pack.Execute();
  1150. result.Should().Pass();
  1151. var outputPath = pack.GetOutputDirectory("net5.0", "Debug").ToString();
  1152. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1153. var packagePath = Path.Combine(
  1154. projectDirectory.Path,
  1155. "bin",
  1156. "Debug",
  1157. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1158. result.Should().NuPkgDoesNotContain(
  1159. packagePath,
  1160. filePaths: new[]
  1161. {
  1162. Path.Combine("content", "exampleJsInterop.js"),
  1163. Path.Combine("content", "background.png"),
  1164. Path.Combine("content", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1165. Path.Combine("contentFiles", "exampleJsInterop.js"),
  1166. Path.Combine("contentFiles", "background.png"),
  1167. Path.Combine("contentFiles", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1168. });
  1169. }
  1170. [Fact]
  1171. public void Pack_BeforeNet60_MultipleTargetFrameworks_NoBuild_WithScopedCss_IncludesAssetsAndProjectBundle()
  1172. {
  1173. var testAsset = "PackageLibraryTransitiveDependency";
  1174. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1175. projectDirectory.WithProjectChanges(document =>
  1176. {
  1177. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1178. <PropertyGroup>
  1179. <TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
  1180. <RazorLangVersion>3.0</RazorLangVersion>
  1181. </PropertyGroup>
  1182. <ItemGroup>
  1183. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1184. <PackageReference Condition=""'$(TargetFramework)' == 'netstandard2.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""3.1.0"" />
  1185. </ItemGroup>
  1186. </Project>
  1187. ");
  1188. document.Root.ReplaceWith(parse.Root);
  1189. });
  1190. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1191. var componentText = @"<div class=""my-component"">
  1192. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1193. </div>";
  1194. // This mimics the structure of our default template project
  1195. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1196. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1197. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1198. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1199. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1200. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1201. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1202. var build = new BuildCommand(Log, projectDirectory.Path);
  1203. build.WithWorkingDirectory(projectDirectory.Path);
  1204. var buildResult = build.Execute();
  1205. buildResult.Should().Pass();
  1206. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1207. pack.WithWorkingDirectory(projectDirectory.Path);
  1208. var result = pack.Execute("/p:NoBuild=true");
  1209. result.Should().Pass();
  1210. var outputPath = pack.GetOutputDirectory("net5.0", "Debug").ToString();
  1211. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1212. var packagePath = Path.Combine(
  1213. projectDirectory.Path,
  1214. "bin",
  1215. "Debug",
  1216. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1217. result.Should().NuPkgContain(
  1218. packagePath,
  1219. filePaths: new[]
  1220. {
  1221. Path.Combine("staticwebassets", "exampleJsInterop.js"),
  1222. Path.Combine("staticwebassets", "background.png"),
  1223. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1224. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  1225. Path.Combine("build", "PackageLibraryTransitiveDependency.props"),
  1226. Path.Combine("buildMultiTargeting", "PackageLibraryTransitiveDependency.props"),
  1227. Path.Combine("buildTransitive", "PackageLibraryTransitiveDependency.props")
  1228. });
  1229. }
  1230. [Fact]
  1231. public void Pack_BeforeNet60_MultipleTargetFrameworks_NoBuild_WithScopedCss_DoesNotIncludeAssetsAsContent()
  1232. {
  1233. var testAsset = "PackageLibraryTransitiveDependency";
  1234. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1235. projectDirectory.WithProjectChanges(document =>
  1236. {
  1237. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1238. <PropertyGroup>
  1239. <TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
  1240. <RazorLangVersion>3.0</RazorLangVersion>
  1241. </PropertyGroup>
  1242. <ItemGroup>
  1243. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1244. <PackageReference Condition=""'$(TargetFramework)' == 'netstandard2.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""3.1.0"" />
  1245. </ItemGroup>
  1246. </Project>
  1247. ");
  1248. document.Root.ReplaceWith(parse.Root);
  1249. });
  1250. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1251. var componentText = @"<div class=""my-component"">
  1252. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1253. </div>";
  1254. // This mimics the structure of our default template project
  1255. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1256. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1257. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1258. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1259. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1260. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1261. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1262. var build = new BuildCommand(Log, projectDirectory.Path);
  1263. build.WithWorkingDirectory(projectDirectory.Path);
  1264. var buildResult = build.Execute();
  1265. buildResult.Should().Pass();
  1266. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1267. pack.WithWorkingDirectory(projectDirectory.Path);
  1268. var result = pack.Execute("/p:NoBuild=true");
  1269. result.Should().Pass();
  1270. var outputPath = pack.GetOutputDirectory("net5.0", "Debug").ToString();
  1271. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1272. var packagePath = Path.Combine(
  1273. projectDirectory.Path,
  1274. "bin",
  1275. "Debug",
  1276. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1277. result.Should().NuPkgDoesNotContain(
  1278. packagePath,
  1279. filePaths: new[]
  1280. {
  1281. Path.Combine("content", "exampleJsInterop.js"),
  1282. Path.Combine("content", "background.png"),
  1283. Path.Combine("content", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1284. Path.Combine("contentFiles", "exampleJsInterop.js"),
  1285. Path.Combine("contentFiles", "background.png"),
  1286. Path.Combine("contentFiles", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1287. });
  1288. }
  1289. [Fact]
  1290. public void Pack_BeforeNet60_MultipleTargetFrameworks_GeneratePackageOnBuild_WithScopedCss_IncludesAssetsAndProjectBundle()
  1291. {
  1292. var testAsset = "PackageLibraryTransitiveDependency";
  1293. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1294. projectDirectory.WithProjectChanges(document =>
  1295. {
  1296. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1297. <PropertyGroup>
  1298. <TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
  1299. <RazorLangVersion>3.0</RazorLangVersion>
  1300. </PropertyGroup>
  1301. <ItemGroup>
  1302. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1303. <PackageReference Condition=""'$(TargetFramework)' == 'netstandard2.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""3.1.0"" />
  1304. </ItemGroup>
  1305. </Project>
  1306. ");
  1307. document.Root.ReplaceWith(parse.Root);
  1308. });
  1309. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1310. var componentText = @"<div class=""my-component"">
  1311. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1312. </div>";
  1313. // This mimics the structure of our default template project
  1314. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1315. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1316. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1317. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1318. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1319. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1320. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1321. var build = new BuildCommand(Log, projectDirectory.Path);
  1322. build.WithWorkingDirectory(projectDirectory.Path);
  1323. var result = build.Execute("/p:GeneratePackageOnBuild=true");
  1324. result.Should().Pass();
  1325. var outputPath = build.GetOutputDirectory("net5.0", "Debug").ToString();
  1326. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1327. var packagePath = Path.Combine(
  1328. projectDirectory.Path,
  1329. "bin",
  1330. "Debug",
  1331. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1332. result.Should().NuPkgContain(
  1333. packagePath,
  1334. filePaths: new[]
  1335. {
  1336. Path.Combine("staticwebassets", "exampleJsInterop.js"),
  1337. Path.Combine("staticwebassets", "background.png"),
  1338. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1339. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  1340. Path.Combine("build", "PackageLibraryTransitiveDependency.props"),
  1341. Path.Combine("buildMultiTargeting", "PackageLibraryTransitiveDependency.props"),
  1342. Path.Combine("buildTransitive", "PackageLibraryTransitiveDependency.props")
  1343. });
  1344. }
  1345. [Fact]
  1346. public void Pack_BeforeNet60_MultipleTargetFrameworks_GeneratePackageOnBuild_WithScopedCss_DoesNotIncludeAssetsAsContent()
  1347. {
  1348. var testAsset = "PackageLibraryTransitiveDependency";
  1349. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1350. projectDirectory.WithProjectChanges(document =>
  1351. {
  1352. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1353. <PropertyGroup>
  1354. <TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
  1355. <RazorLangVersion>3.0</RazorLangVersion>
  1356. </PropertyGroup>
  1357. <ItemGroup>
  1358. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1359. <PackageReference Condition=""'$(TargetFramework)' == 'netstandard2.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""3.1.0"" />
  1360. </ItemGroup>
  1361. </Project>
  1362. ");
  1363. document.Root.ReplaceWith(parse.Root);
  1364. });
  1365. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1366. var componentText = @"<div class=""my-component"">
  1367. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1368. </div>";
  1369. // This mimics the structure of our default template project
  1370. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1371. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1372. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1373. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1374. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1375. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1376. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1377. var build = new BuildCommand(Log, projectDirectory.Path);
  1378. build.WithWorkingDirectory(projectDirectory.Path);
  1379. var result = build.Execute("/p:GeneratePackageOnBuild=true");
  1380. result.Should().Pass();
  1381. var outputPath = build.GetOutputDirectory("net5.0", "Debug").ToString();
  1382. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1383. var packagePath = Path.Combine(
  1384. projectDirectory.Path,
  1385. "bin",
  1386. "Debug",
  1387. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1388. result.Should().NuPkgDoesNotContain(
  1389. packagePath,
  1390. filePaths: new[]
  1391. {
  1392. Path.Combine("content", "exampleJsInterop.js"),
  1393. Path.Combine("content", "background.png"),
  1394. Path.Combine("content", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1395. Path.Combine("contentFiles", "exampleJsInterop.js"),
  1396. Path.Combine("contentFiles", "background.png"),
  1397. Path.Combine("contentFiles", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1398. });
  1399. }
  1400. [Fact]
  1401. public void Pack_Net50_WithScopedCss_IncludesAssetsAndProjectBundle()
  1402. {
  1403. var testAsset = "PackageLibraryTransitiveDependency";
  1404. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1405. projectDirectory.WithProjectChanges(document =>
  1406. {
  1407. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1408. <PropertyGroup>
  1409. <TargetFramework>net5.0</TargetFramework>
  1410. </PropertyGroup>
  1411. <ItemGroup>
  1412. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1413. </ItemGroup>
  1414. </Project>
  1415. ");
  1416. document.Root.ReplaceWith(parse.Root);
  1417. });
  1418. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1419. var componentText = @"<div class=""my-component"">
  1420. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1421. </div>";
  1422. // This mimics the structure of our default template project
  1423. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1424. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1425. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1426. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1427. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1428. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1429. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1430. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1431. pack.WithWorkingDirectory(projectDirectory.Path);
  1432. var result = pack.Execute();
  1433. result.Should().Pass();
  1434. var outputPath = pack.GetOutputDirectory("net5.0", "Debug").ToString();
  1435. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1436. var packagePath = Path.Combine(
  1437. projectDirectory.Path,
  1438. "bin",
  1439. "Debug",
  1440. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1441. result.Should().NuPkgContain(
  1442. packagePath,
  1443. filePaths: new[]
  1444. {
  1445. Path.Combine("staticwebassets", "exampleJsInterop.js"),
  1446. Path.Combine("staticwebassets", "background.png"),
  1447. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1448. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  1449. Path.Combine("build", "PackageLibraryTransitiveDependency.props"),
  1450. Path.Combine("buildMultiTargeting", "PackageLibraryTransitiveDependency.props"),
  1451. Path.Combine("buildTransitive", "PackageLibraryTransitiveDependency.props")
  1452. });
  1453. }
  1454. [Fact]
  1455. public void Pack_Net50_WithScopedCss_DoesNotIncludeAssetsAsContent()
  1456. {
  1457. var testAsset = "PackageLibraryTransitiveDependency";
  1458. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1459. projectDirectory.WithProjectChanges(document =>
  1460. {
  1461. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1462. <PropertyGroup>
  1463. <TargetFramework>net5.0</TargetFramework>
  1464. </PropertyGroup>
  1465. <ItemGroup>
  1466. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1467. </ItemGroup>
  1468. </Project>
  1469. ");
  1470. document.Root.ReplaceWith(parse.Root);
  1471. });
  1472. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1473. var componentText = @"<div class=""my-component"">
  1474. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1475. </div>";
  1476. // This mimics the structure of our default template project
  1477. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1478. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1479. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1480. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1481. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1482. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1483. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1484. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1485. pack.WithWorkingDirectory(projectDirectory.Path);
  1486. var result = pack.Execute();
  1487. result.Should().Pass();
  1488. var outputPath = pack.GetOutputDirectory("net5.0", "Debug").ToString();
  1489. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1490. var packagePath = Path.Combine(
  1491. projectDirectory.Path,
  1492. "bin",
  1493. "Debug",
  1494. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1495. result.Should().NuPkgDoesNotContain(
  1496. packagePath,
  1497. filePaths: new[]
  1498. {
  1499. Path.Combine("content", "exampleJsInterop.js"),
  1500. Path.Combine("content", "background.png"),
  1501. Path.Combine("content", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1502. Path.Combine("contentFiles", "exampleJsInterop.js"),
  1503. Path.Combine("contentFiles", "background.png"),
  1504. Path.Combine("contentFiles", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1505. });
  1506. }
  1507. [Fact]
  1508. public void Pack_Net50_NoBuild_WithScopedCss_IncludesAssetsAndProjectBundle()
  1509. {
  1510. var testAsset = "PackageLibraryTransitiveDependency";
  1511. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1512. projectDirectory.WithProjectChanges(document =>
  1513. {
  1514. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1515. <PropertyGroup>
  1516. <TargetFramework>net5.0</TargetFramework>
  1517. </PropertyGroup>
  1518. <ItemGroup>
  1519. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1520. </ItemGroup>
  1521. </Project>
  1522. ");
  1523. document.Root.ReplaceWith(parse.Root);
  1524. });
  1525. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1526. var componentText = @"<div class=""my-component"">
  1527. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1528. </div>";
  1529. // This mimics the structure of our default template project
  1530. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1531. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1532. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1533. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1534. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1535. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1536. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1537. var build = new BuildCommand(Log, projectDirectory.Path);
  1538. build.WithWorkingDirectory(projectDirectory.Path);
  1539. var buildResult = build.Execute();
  1540. buildResult.Should().Pass();
  1541. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1542. pack.WithWorkingDirectory(projectDirectory.Path);
  1543. var result = pack.Execute("/p:NoBuild=true");
  1544. result.Should().Pass();
  1545. var outputPath = pack.GetOutputDirectory("net5.0", "Debug").ToString();
  1546. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1547. var packagePath = Path.Combine(
  1548. projectDirectory.Path,
  1549. "bin",
  1550. "Debug",
  1551. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1552. result.Should().NuPkgContain(
  1553. packagePath,
  1554. filePaths: new[]
  1555. {
  1556. Path.Combine("staticwebassets", "exampleJsInterop.js"),
  1557. Path.Combine("staticwebassets", "background.png"),
  1558. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1559. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  1560. Path.Combine("build", "PackageLibraryTransitiveDependency.props"),
  1561. Path.Combine("buildMultiTargeting", "PackageLibraryTransitiveDependency.props"),
  1562. Path.Combine("buildTransitive", "PackageLibraryTransitiveDependency.props")
  1563. });
  1564. }
  1565. [Fact]
  1566. public void Pack_Net50_NoBuild_WithScopedCss_DoesNotIncludeAssetsAsContent()
  1567. {
  1568. var testAsset = "PackageLibraryTransitiveDependency";
  1569. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1570. projectDirectory.WithProjectChanges(document =>
  1571. {
  1572. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1573. <PropertyGroup>
  1574. <TargetFramework>net5.0</TargetFramework>
  1575. </PropertyGroup>
  1576. <ItemGroup>
  1577. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1578. </ItemGroup>
  1579. </Project>
  1580. ");
  1581. document.Root.ReplaceWith(parse.Root);
  1582. });
  1583. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1584. var componentText = @"<div class=""my-component"">
  1585. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1586. </div>";
  1587. // This mimics the structure of our default template project
  1588. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1589. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1590. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1591. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1592. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1593. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1594. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1595. var build = new BuildCommand(Log, projectDirectory.Path);
  1596. build.WithWorkingDirectory(projectDirectory.Path);
  1597. var buildResult = build.Execute();
  1598. buildResult.Should().Pass();
  1599. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1600. pack.WithWorkingDirectory(projectDirectory.Path);
  1601. var result = pack.Execute("/p:NoBuild=true");
  1602. result.Should().Pass();
  1603. var outputPath = pack.GetOutputDirectory("net5.0", "Debug").ToString();
  1604. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1605. var packagePath = Path.Combine(
  1606. projectDirectory.Path,
  1607. "bin",
  1608. "Debug",
  1609. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1610. result.Should().NuPkgDoesNotContain(
  1611. packagePath,
  1612. filePaths: new[]
  1613. {
  1614. Path.Combine("content", "exampleJsInterop.js"),
  1615. Path.Combine("content", "background.png"),
  1616. Path.Combine("content", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1617. Path.Combine("contentFiles", "exampleJsInterop.js"),
  1618. Path.Combine("contentFiles", "background.png"),
  1619. Path.Combine("contentFiles", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1620. });
  1621. }
  1622. [Fact]
  1623. public void Pack_Net50_GeneratePackageOnBuild_WithScopedCss_IncludesAssetsAndProjectBundle()
  1624. {
  1625. var testAsset = "PackageLibraryTransitiveDependency";
  1626. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1627. projectDirectory.WithProjectChanges(document =>
  1628. {
  1629. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1630. <PropertyGroup>
  1631. <TargetFramework>net5.0</TargetFramework>
  1632. </PropertyGroup>
  1633. <ItemGroup>
  1634. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1635. </ItemGroup>
  1636. </Project>
  1637. ");
  1638. document.Root.ReplaceWith(parse.Root);
  1639. });
  1640. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1641. var componentText = @"<div class=""my-component"">
  1642. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1643. </div>";
  1644. // This mimics the structure of our default template project
  1645. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1646. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1647. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1648. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1649. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1650. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1651. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1652. var build = new BuildCommand(Log, projectDirectory.Path);
  1653. build.WithWorkingDirectory(projectDirectory.Path);
  1654. var result = build.Execute("/p:GeneratePackageOnBuild=true");
  1655. result.Should().Pass();
  1656. var outputPath = build.GetOutputDirectory("net5.0", "Debug").ToString();
  1657. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1658. var packagePath = Path.Combine(
  1659. projectDirectory.Path,
  1660. "bin",
  1661. "Debug",
  1662. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1663. result.Should().NuPkgContain(
  1664. packagePath,
  1665. filePaths: new[]
  1666. {
  1667. Path.Combine("staticwebassets", "exampleJsInterop.js"),
  1668. Path.Combine("staticwebassets", "background.png"),
  1669. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1670. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  1671. Path.Combine("build", "PackageLibraryTransitiveDependency.props"),
  1672. Path.Combine("buildMultiTargeting", "PackageLibraryTransitiveDependency.props"),
  1673. Path.Combine("buildTransitive", "PackageLibraryTransitiveDependency.props")
  1674. });
  1675. }
  1676. [Fact]
  1677. public void Pack_Net50_GeneratePackageOnBuild_WithScopedCss_DoesNotIncludeAssetsAsContent()
  1678. {
  1679. var testAsset = "PackageLibraryTransitiveDependency";
  1680. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1681. projectDirectory.WithProjectChanges(document =>
  1682. {
  1683. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1684. <PropertyGroup>
  1685. <TargetFramework>net5.0</TargetFramework>
  1686. </PropertyGroup>
  1687. <ItemGroup>
  1688. <PackageReference Condition=""'$(TargetFramework)' == 'net5.0'"" Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1689. </ItemGroup>
  1690. </Project>
  1691. ");
  1692. document.Root.ReplaceWith(parse.Root);
  1693. });
  1694. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1695. var componentText = @"<div class=""my-component"">
  1696. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1697. </div>";
  1698. // This mimics the structure of our default template project
  1699. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1700. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1701. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1702. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1703. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1704. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1705. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1706. var build = new BuildCommand(Log, projectDirectory.Path);
  1707. build.WithWorkingDirectory(projectDirectory.Path);
  1708. var result = build.Execute("/p:GeneratePackageOnBuild=true");
  1709. result.Should().Pass();
  1710. var outputPath = build.GetOutputDirectory("net5.0", "Debug").ToString();
  1711. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1712. var packagePath = Path.Combine(
  1713. projectDirectory.Path,
  1714. "bin",
  1715. "Debug",
  1716. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1717. result.Should().NuPkgDoesNotContain(
  1718. packagePath,
  1719. filePaths: new[]
  1720. {
  1721. Path.Combine("content", "exampleJsInterop.js"),
  1722. Path.Combine("content", "background.png"),
  1723. Path.Combine("content", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1724. Path.Combine("contentFiles", "exampleJsInterop.js"),
  1725. Path.Combine("contentFiles", "background.png"),
  1726. Path.Combine("contentFiles", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1727. });
  1728. }
  1729. [Fact]
  1730. public void Pack_MultipleTargetFrameworks_WithScopedCssAndJsModules_IncludesAssetsAndProjectBundle()
  1731. {
  1732. var testAsset = "PackageLibraryTransitiveDependency";
  1733. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1734. projectDirectory.WithProjectChanges(document =>
  1735. {
  1736. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1737. <PropertyGroup>
  1738. <TargetFrameworks>{ToolsetInfo.CurrentTargetFramework};net8.0;net7.0;net6.0;net5.0</TargetFrameworks>
  1739. <Nullable>enable</Nullable>
  1740. </PropertyGroup>
  1741. <ItemGroup>
  1742. <SupportedPlatform Condition=""'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == '{ToolsetInfo.CurrentTargetFramework}'"" Include=""browser"" />
  1743. </ItemGroup>
  1744. <ItemGroup>
  1745. <PackageReference Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1746. </ItemGroup>
  1747. </Project>
  1748. ");
  1749. document.Root.ReplaceWith(parse.Root);
  1750. });
  1751. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1752. var componentText = @"<div class=""my-component"">
  1753. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1754. </div>";
  1755. // This mimics the structure of our default template project
  1756. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1757. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1758. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1759. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1760. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.js"), "");
  1761. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1762. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1763. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "PackageLibraryTransitiveDependency.lib.module.js"), "");
  1764. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1765. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1766. pack.WithWorkingDirectory(projectDirectory.Path);
  1767. var result = pack.Execute("/bl");
  1768. result.Should().Pass();
  1769. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  1770. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1771. var packagePath = Path.Combine(
  1772. projectDirectory.Path,
  1773. "bin",
  1774. "Debug",
  1775. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1776. result.Should().NuPkgContain(
  1777. packagePath,
  1778. filePaths: new[]
  1779. {
  1780. Path.Combine("staticwebassets", "exampleJsInterop.js"),
  1781. Path.Combine("staticwebassets", "background.png"),
  1782. Path.Combine("staticwebassets", "Component1.razor.js"),
  1783. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1784. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.lib.module.js"),
  1785. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  1786. Path.Combine("build", "PackageLibraryTransitiveDependency.props"),
  1787. Path.Combine("buildMultiTargeting", "PackageLibraryTransitiveDependency.props"),
  1788. Path.Combine("buildTransitive", "PackageLibraryTransitiveDependency.props")
  1789. });
  1790. }
  1791. [Fact]
  1792. public void Pack_Incremental_MultipleTargetFrameworks_WithScopedCssAndJsModules_IncludesAssetsAndProjectBundle()
  1793. {
  1794. var testAsset = "PackageLibraryTransitiveDependency";
  1795. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1796. projectDirectory.WithProjectChanges(document =>
  1797. {
  1798. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1799. <PropertyGroup>
  1800. <TargetFrameworks>{ToolsetInfo.CurrentTargetFramework};net8.0;net7.0;net6.0;net5.0</TargetFrameworks>
  1801. <Nullable>enable</Nullable>
  1802. </PropertyGroup>
  1803. <ItemGroup>
  1804. <SupportedPlatform Condition=""'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == '{ToolsetInfo.CurrentTargetFramework}'"" Include=""browser"" />
  1805. </ItemGroup>
  1806. <ItemGroup>
  1807. <PackageReference Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1808. </ItemGroup>
  1809. </Project>
  1810. ");
  1811. document.Root.ReplaceWith(parse.Root);
  1812. });
  1813. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1814. var componentText = @"<div class=""my-component"">
  1815. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1816. </div>";
  1817. // This mimics the structure of our default template project
  1818. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1819. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1820. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1821. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1822. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.js"), "");
  1823. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1824. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1825. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "PackageLibraryTransitiveDependency.lib.module.js"), "");
  1826. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1827. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1828. var pack2 = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1829. pack2.WithWorkingDirectory(projectDirectory.Path);
  1830. var result2 = pack2.Execute();
  1831. result2.Should().Pass();
  1832. var outputPath = pack2.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  1833. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1834. var packagePath = Path.Combine(
  1835. projectDirectory.Path,
  1836. "bin",
  1837. "Debug",
  1838. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1839. result2.Should().NuPkgContain(
  1840. packagePath,
  1841. filePaths: new[]
  1842. {
  1843. Path.Combine("staticwebassets", "exampleJsInterop.js"),
  1844. Path.Combine("staticwebassets", "background.png"),
  1845. Path.Combine("staticwebassets", "Component1.razor.js"),
  1846. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.bundle.scp.css"),
  1847. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.lib.module.js"),
  1848. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  1849. Path.Combine("build", "PackageLibraryTransitiveDependency.props"),
  1850. Path.Combine("buildMultiTargeting", "PackageLibraryTransitiveDependency.props"),
  1851. Path.Combine("buildTransitive", "PackageLibraryTransitiveDependency.props")
  1852. });
  1853. }
  1854. [Fact]
  1855. public void Pack_MultipleTargetFrameworks_WithScopedCssAndJsModules_DoesNotIncludeApplicationBundleNorModulesManifest()
  1856. {
  1857. var testAsset = "PackageLibraryTransitiveDependency";
  1858. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1859. projectDirectory.WithProjectChanges(document =>
  1860. {
  1861. var parse = XDocument.Parse($@"<Project Sdk=""Microsoft.NET.Sdk.Razor"">
  1862. <PropertyGroup>
  1863. <TargetFrameworks>{ToolsetInfo.CurrentTargetFramework};net8.0;net7.0;net6.0;net5.0</TargetFrameworks>
  1864. <Nullable>enable</Nullable>
  1865. </PropertyGroup>
  1866. <ItemGroup>
  1867. <SupportedPlatform Condition=""'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == '{ToolsetInfo.CurrentTargetFramework}'"" Include=""browser"" />
  1868. </ItemGroup>
  1869. <ItemGroup>
  1870. <PackageReference Include=""Microsoft.AspNetCore.Components.Web"" Version=""{DefaultPackageVersion}"" />
  1871. </ItemGroup>
  1872. </Project>
  1873. ");
  1874. document.Root.ReplaceWith(parse.Root);
  1875. });
  1876. Directory.Delete(Path.Combine(projectDirectory.Path, "wwwroot"), recursive: true);
  1877. var componentText = @"<div class=""my-component"">
  1878. This component is defined in the <strong>razorclasslibrarypack</strong> library.
  1879. </div>";
  1880. // This mimics the structure of our default template project
  1881. Directory.CreateDirectory(Path.Combine(projectDirectory.Path, "wwwroot"));
  1882. File.WriteAllText(Path.Combine(projectDirectory.Path, "_Imports.razor"), "@using Microsoft.AspNetCore.Components.Web" + Environment.NewLine);
  1883. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor"), componentText);
  1884. File.WriteAllText(Path.Combine(projectDirectory.Path, "Component1.razor.css"), "");
  1885. File.WriteAllText(Path.Combine(projectDirectory.Path, "ExampleJsInterop.cs"), "");
  1886. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "background.png"), "");
  1887. File.WriteAllText(Path.Combine(projectDirectory.Path, "wwwroot", "exampleJsInterop.js"), "");
  1888. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  1889. pack.WithWorkingDirectory(projectDirectory.Path);
  1890. var result = pack.Execute();
  1891. result.Should().Pass();
  1892. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  1893. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  1894. var packagePath = Path.Combine(
  1895. projectDirectory.Path,
  1896. "bin",
  1897. "Debug",
  1898. "PackageLibraryTransitiveDependency.1.0.0.nupkg");
  1899. result.Should().NuPkgDoesNotContain(
  1900. packagePath,
  1901. filePaths: new[]
  1902. {
  1903. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.styles.css"),
  1904. Path.Combine("staticwebassets", "PackageLibraryTransitiveDependency.modules.json"),
  1905. });
  1906. }
  1907. [Fact]
  1908. public void Pack_MultipleTargetFrameworks_DoesNotIncludeAssetsAsContent()
  1909. {
  1910. var testAsset = "PackageLibraryDirectDependency";
  1911. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1912. projectDirectory.WithProjectChanges((project, document) =>
  1913. {
  1914. var tfm = document.Descendants("TargetFramework").Single();
  1915. tfm.Name = "TargetFrameworks";
  1916. tfm.FirstNode.ReplaceWith(tfm.FirstNode.ToString() + ";netstandard2.1");
  1917. document.Descendants("AddRazorSupportForMvc").SingleOrDefault()?.Remove();
  1918. document.Descendants("FrameworkReference").SingleOrDefault()?.Remove();
  1919. });
  1920. Directory.Delete(Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "Components"), recursive: true);
  1921. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  1922. pack.WithWorkingDirectory(projectDirectory.Path);
  1923. var result = pack.Execute();
  1924. result.Should().Pass();
  1925. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  1926. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  1927. result.Should().NuPkgDoesNotContain(
  1928. Path.Combine(projectDirectory.Path, "PackageLibraryDirectDependency", "bin", "Debug", "PackageLibraryDirectDependency.1.0.0.nupkg"),
  1929. filePaths: new[]
  1930. {
  1931. Path.Combine("content", "wwwroot", "js", "pkg-direct-dep.js"),
  1932. Path.Combine("content", "wwwroot", "css", "site.css"),
  1933. Path.Combine("contentFiles", "wwwroot", "js", "pkg-direct-dep.js"),
  1934. Path.Combine("contentFiles", "wwwroot", "css", "site.css"),
  1935. });
  1936. }
  1937. [Fact]
  1938. public void Pack_DoesNotInclude_TransitiveBundleOrScopedCssAsStaticWebAsset()
  1939. {
  1940. var testAsset = "PackageLibraryDirectDependency";
  1941. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1942. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  1943. pack.WithWorkingDirectory(projectDirectory.TestRoot);
  1944. var result = pack.Execute();
  1945. result.Should().Pass();
  1946. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  1947. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  1948. result.Should().NuPkgDoesNotContain(
  1949. Path.Combine(pack.GetPackageDirectory().FullName, "PackageLibraryDirectDependency.1.0.0.nupkg"),
  1950. filePaths: new[]
  1951. {
  1952. // This is to make sure we don't include the scoped css files on the package when bundling is enabled.
  1953. Path.Combine("staticwebassets", "Components", "App.razor.rz.scp.css"),
  1954. Path.Combine("staticwebassets", "PackageLibraryDirectDependency.styles.css"),
  1955. });
  1956. }
  1957. [Fact]
  1958. public void Pack_DoesNotIncludeStaticWebAssetsAsContent()
  1959. {
  1960. var testAsset = "PackageLibraryDirectDependency";
  1961. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1962. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  1963. var result = pack.Execute();
  1964. result.Should().Pass();
  1965. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  1966. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  1967. result.Should().NuPkgDoesNotContain(
  1968. Path.Combine(pack.GetPackageDirectory().FullName, "PackageLibraryDirectDependency.1.0.0.nupkg"),
  1969. filePaths: new[]
  1970. {
  1971. Path.Combine("content", "wwwroot", "js", "pkg-direct-dep.js"),
  1972. Path.Combine("content", "wwwroot", "css", "site.css"),
  1973. Path.Combine("content", "Components", "App.razor.css"),
  1974. // This is to make sure we don't include the unscoped css file on the package.
  1975. Path.Combine("content", "Components", "App.razor.css"),
  1976. Path.Combine("content", "Components", "App.razor.rz.scp.css"),
  1977. Path.Combine("contentFiles", "wwwroot", "js", "pkg-direct-dep.js"),
  1978. Path.Combine("contentFiles", "wwwroot", "css", "site.css"),
  1979. Path.Combine("contentFiles", "Components", "App.razor.css"),
  1980. Path.Combine("contentFiles", "Components", "App.razor.rz.scp.css"),
  1981. });
  1982. }
  1983. [Fact]
  1984. public void Pack_NoBuild_IncludesStaticWebAssets()
  1985. {
  1986. var testAsset = "PackageLibraryDirectDependency";
  1987. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  1988. var build = new BuildCommand(projectDirectory, "PackageLibraryDirectDependency");
  1989. build.Execute().Should().Pass();
  1990. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  1991. pack.WithWorkingDirectory(projectDirectory.TestRoot);
  1992. var result = pack.Execute("/p:NoBuild=true");
  1993. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  1994. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  1995. result.Should().NuPkgContain(
  1996. Path.Combine(build.GetPackageDirectory().FullName, "PackageLibraryDirectDependency.1.0.0.nupkg"),
  1997. filePaths: new[]
  1998. {
  1999. Path.Combine("staticwebassets", "js", "pkg-direct-dep.js"),
  2000. Path.Combine("staticwebassets", "PackageLibraryDirectDependency.bundle.scp.css"),
  2001. Path.Combine("staticwebassets", "css", "site.css"),
  2002. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  2003. Path.Combine("build", "PackageLibraryDirectDependency.props"),
  2004. Path.Combine("buildMultiTargeting", "PackageLibraryDirectDependency.props"),
  2005. Path.Combine("buildTransitive", "PackageLibraryDirectDependency.props")
  2006. });
  2007. }
  2008. [Fact]
  2009. public void Pack_NoBuild_DoesNotIncludeFilesAsContent()
  2010. {
  2011. var testAsset = "PackageLibraryDirectDependency";
  2012. var projectDirectory = CreateAspNetSdkTestAsset(testAsset, subdirectory: "TestPackages");
  2013. var build = new BuildCommand(projectDirectory, "PackageLibraryDirectDependency");
  2014. build.Execute().Should().Pass();
  2015. var pack = new MSBuildCommand(projectDirectory, "Pack", "PackageLibraryDirectDependency");
  2016. pack.WithWorkingDirectory(projectDirectory.TestRoot);
  2017. var result = pack.Execute("/p:NoBuild=true");
  2018. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  2019. new FileInfo(Path.Combine(outputPath, "PackageLibraryDirectDependency.dll")).Should().Exist();
  2020. result.Should().NuPkgDoesNotContain(
  2021. Path.Combine(pack.GetPackageDirectory().FullName, "PackageLibraryDirectDependency.1.0.0.nupkg"),
  2022. filePaths: new[]
  2023. {
  2024. Path.Combine("content", "wwwroot", "js", "pkg-direct-dep.js"),
  2025. Path.Combine("content", "PackageLibraryDirectDependency.bundle.scp.css"),
  2026. Path.Combine("content", "wwwroot", "css", "site.css"),
  2027. Path.Combine("contentFiles", "wwwroot", "js", "pkg-direct-dep.js"),
  2028. Path.Combine("contentFiles", "PackageLibraryDirectDependency.bundle.scp.css"),
  2029. Path.Combine("contentFiles", "wwwroot", "css", "site.css"),
  2030. });
  2031. }
  2032. [Fact]
  2033. public void Pack_DoesNotIncludeAnyCustomPropsFiles_WhenNoStaticAssetsAreAvailable()
  2034. {
  2035. var testAsset = "RazorComponentLibrary";
  2036. var projectDirectory = CreateAspNetSdkTestAsset(testAsset);
  2037. var pack = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  2038. var result = pack.Execute();
  2039. var outputPath = pack.GetOutputDirectory("netstandard2.0", "Debug").ToString();
  2040. new FileInfo(Path.Combine(outputPath, "ComponentLibrary.dll")).Should().Exist();
  2041. result.Should().NuPkgDoesNotContain(
  2042. Path.Combine(projectDirectory.Path, "bin", "Debug", "ComponentLibrary.1.0.0.nupkg"),
  2043. filePaths: new[]
  2044. {
  2045. Path.Combine("build", "Microsoft.AspNetCore.StaticWebAssets.props"),
  2046. Path.Combine("build", "ComponentLibrary.props"),
  2047. Path.Combine("buildMultiTargeting", "ComponentLibrary.props"),
  2048. Path.Combine("buildTransitive", "ComponentLibrary.props")
  2049. });
  2050. }
  2051. [Fact]
  2052. public void Pack_Incremental_DoesNotRegenerateCacheAndPropsFiles()
  2053. {
  2054. var testAsset = "PackageLibraryTransitiveDependency";
  2055. var projectDirectory = _testAssetsManager
  2056. .CopyTestAsset(testAsset, testAssetSubdirectory: "TestPackages")
  2057. .WithSource();
  2058. var pack = new MSBuildCommand(projectDirectory, "Pack");
  2059. pack.WithWorkingDirectory(projectDirectory.TestRoot);
  2060. var result = pack.Execute();
  2061. var intermediateOutputPath = pack.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
  2062. var outputPath = pack.GetOutputDirectory(DefaultTfm, "Debug").ToString();
  2063. new FileInfo(Path.Combine(outputPath, "PackageLibraryTransitiveDependency.dll")).Should().Exist();
  2064. new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "msbuild.PackageLibraryTransitiveDependency.Microsoft.AspNetCore.StaticWebAssets.props")).Should().Exist();
  2065. new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "msbuild.build.PackageLibraryTransitiveDependency.props")).Should().Exist();
  2066. new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "msbuild.buildMultiTargeting.PackageLibraryTransitiveDependency.props")).Should().Exist();
  2067. new FileInfo(Path.Combine(intermediateOutputPath, "staticwebassets", "msbuild.buildTransitive.PackageLibraryTransitiveDependency.props")).Should().Exist();
  2068. var directoryPath = Path.Combine(intermediateOutputPath, "staticwebassets");
  2069. var thumbPrints = new Dictionary<string, FileThumbPrint>();
  2070. var thumbPrintFiles = new[]
  2071. {
  2072. Path.Combine(directoryPath, "msbuild.PackageLibraryTransitiveDependency.Microsoft.AspNetCore.StaticWebAssets.props"),
  2073. Path.Combine(directoryPath, "msbuild.build.PackageLibraryTransitiveDependency.props"),
  2074. Path.Combine(directoryPath, "msbuild.buildMultiTargeting.PackageLibraryTransitiveDependency.props"),
  2075. Path.Combine(directoryPath, "msbuild.buildTransitive.PackageLibraryTransitiveDependency.props"),
  2076. };
  2077. foreach (var file in thumbPrintFiles)
  2078. {
  2079. var thumbprint = FileThumbPrint.Create(file);
  2080. thumbPrints[file] = thumbprint;
  2081. }
  2082. // Act
  2083. var incremental = new MSBuildCommand(Log, "Pack", projectDirectory.Path);
  2084. incremental.Execute().Should().Pass();
  2085. foreach (var file in thumbPrintFiles)
  2086. {
  2087. var thumbprint = FileThumbPrint.Create(file);
  2088. Assert.Equal(thumbPrints[file], thumbprint);
  2089. }
  2090. }
  2091. }
  2092. }