Do not override existing web.config during IIS publish
This commit is contained in:
parent
38285eb9ba
commit
b289633533
|
|
@ -15,25 +15,31 @@
|
||||||
Condition="'$(BlazorPrunePublishOutput)' != 'false'">
|
Condition="'$(BlazorPrunePublishOutput)' != 'false'">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- Delete stray contents from the root of the the app. -->
|
<!-- Delete stray DLLs from the application. -->
|
||||||
<ResolvedFileToPublish
|
<ResolvedFileToPublish
|
||||||
Remove="%(ResolvedFileToPublish.Identity)"
|
Remove="%(ResolvedFileToPublish.Identity)"
|
||||||
Condition="!$([System.String]::Copy('%(ResolvedFileToPublish.RelativePath)').Replace('\','/').StartsWith('wwwroot/'))"/>
|
Condition="$([System.String]::Copy('%(ResolvedFileToPublish.RelativePath)').EndsWith('dll'))"/>
|
||||||
|
<!--Remove stray debugging files.-->
|
||||||
|
<ResolvedFileToPublish
|
||||||
|
Remove="%(ResolvedFileToPublish.Identity)"
|
||||||
|
Condition="$([System.String]::Copy('%(ResolvedFileToPublish.RelativePath)').EndsWith('pdb'))"/>
|
||||||
|
<!--Remove excluded static assets.-->
|
||||||
|
<ResolvedFileToPublish
|
||||||
|
Remove="%(ResolvedFileToPublish.Identity)"
|
||||||
|
Condition="$([System.String]::Copy('%(ResolvedFileToPublish.RelativePath)').Replace('\','/').StartsWith('Excluded-Static-Web-Assets/'))"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
|
<!--After moving the resolved files to the publish directory, we can determine
|
||||||
|
whether or not to copy the standalone config if the user has not provided
|
||||||
|
their own.-->
|
||||||
<Target
|
<Target
|
||||||
Name="_BlazorCopyStandaloneWebConfig"
|
Name="_BlazorCopyStandaloneWebConfig"
|
||||||
AfterTargets="_BlazorCleanupPublishOutput;ComputeResolvedFilesToPublishList">
|
AfterTargets="CopyFilesToPublishDirectory"
|
||||||
|
Condition="!Exists('$(PublishDir)web.config')">
|
||||||
<ItemGroup>
|
<WriteLinesToFile
|
||||||
<ResolvedFileToPublish Include="$(MSBuildThisFileDirectory)Standalone.Web.config">
|
File="$(PublishDir)web.config"
|
||||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
Lines="$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)Standalone.Web.config'))" />
|
||||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
|
||||||
<RelativePath>web.config</RelativePath>
|
|
||||||
</ResolvedFileToPublish>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,29 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
||||||
Assert.FileCountEquals(result, 1, publishDirectory, "*", SearchOption.TopDirectoryOnly);
|
Assert.FileCountEquals(result, 1, publishDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Publish_WithExistingWebConfig_Works()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using var project = ProjectDirectory.Create("standalone", additionalProjects: new[] { "razorclasslibrary", "LinkBaseToWebRoot" });
|
||||||
|
project.Configuration = "Release";
|
||||||
|
|
||||||
|
var webConfigContents = "test webconfig contents";
|
||||||
|
AddFileToProject(project, "web.config", webConfigContents);
|
||||||
|
|
||||||
|
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
|
||||||
|
|
||||||
|
Assert.BuildPassed(result);
|
||||||
|
|
||||||
|
var publishDirectory = project.PublishOutputDirectory;
|
||||||
|
|
||||||
|
var blazorPublishDirectory = Path.Combine(publishDirectory, "wwwroot");
|
||||||
|
|
||||||
|
// Verify web.config
|
||||||
|
Assert.FileExists(result, publishDirectory, "web.config");
|
||||||
|
Assert.FileContains(result, Path.Combine(publishDirectory, "web.config"), webConfigContents);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Publish_WithNoBuild_Works()
|
public async Task Publish_WithNoBuild_Works()
|
||||||
{
|
{
|
||||||
|
|
@ -392,6 +415,13 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
||||||
File.WriteAllText(path, updated);
|
File.WriteAllText(path, updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void AddFileToProject(ProjectDirectory project, string filename, string content)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(project.DirectoryPath, filename);
|
||||||
|
File.WriteAllText(path, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void VerifyBootManifestHashes(MSBuildResult result, string blazorPublishDirectory)
|
private static void VerifyBootManifestHashes(MSBuildResult result, string blazorPublishDirectory)
|
||||||
{
|
{
|
||||||
var bootManifestResolvedPath = Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
|
var bootManifestResolvedPath = Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue