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'">
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Delete stray contents from the root of the the app. -->
|
||||
<!-- Delete stray DLLs from the application. -->
|
||||
<ResolvedFileToPublish
|
||||
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>
|
||||
</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
|
||||
Name="_BlazorCopyStandaloneWebConfig"
|
||||
AfterTargets="_BlazorCleanupPublishOutput;ComputeResolvedFilesToPublishList">
|
||||
|
||||
<ItemGroup>
|
||||
<ResolvedFileToPublish Include="$(MSBuildThisFileDirectory)Standalone.Web.config">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
<RelativePath>web.config</RelativePath>
|
||||
</ResolvedFileToPublish>
|
||||
</ItemGroup>
|
||||
|
||||
AfterTargets="CopyFilesToPublishDirectory"
|
||||
Condition="!Exists('$(PublishDir)web.config')">
|
||||
<WriteLinesToFile
|
||||
File="$(PublishDir)web.config"
|
||||
Lines="$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)Standalone.Web.config'))" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -101,6 +101,29 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
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]
|
||||
public async Task Publish_WithNoBuild_Works()
|
||||
{
|
||||
|
|
@ -392,6 +415,13 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
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)
|
||||
{
|
||||
var bootManifestResolvedPath = Assert.FileExists(result, blazorPublishDirectory, "_framework", "blazor.boot.json");
|
||||
|
|
|
|||
Loading…
Reference in New Issue