IISExpress: Relative paths in applicationhost.config
IISExpress which comes with Visual Studio only supports absolute paths to webroot in applicationhost.config. Visual Studio updates this file with actual path when you load web project. Basically you cannot use IISExpress if your web-site is hosted in a different folder other than original webroot. However in solutions with multiple web projects where they are linked to a single common webroot folder it may become a problem. In order to override Visual Studio behavior I wrote MSBUILD script which updates applicationhost.config with necessary path. You'll also need to include applicationhost.config into your web-project as a link to make sure Visual Studio doesn't skip build when file changed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<!-- | |
@author: Raman Zhylich (raman_zhylich@epam.com) | |
This project configures IISExpress in Visual Studio. | |
--> | |
<PropertyGroup> | |
<BuildDependsOn> | |
ConfigureIISExpress; | |
$(BuildDependsOn); | |
</BuildDependsOn> | |
<ApplicationHostConfig>$(SolutionDir).vs\config\applicationhost.config</ApplicationHostConfig> | |
</PropertyGroup> | |
<!-- Automatically configures IISExpress in Visual Studio. Updates virtual directory path in applicationhost.config to point to IISROOT --> | |
<Target Name="ConfigureIISExpress" Condition="Exists('$(ApplicationHostConfig)')"> | |
<PropertyGroup> | |
<VirtualDirectoryPath>$([System.IO.Path]::GetFullPath('$(SolutionDir)..\IISROOT'))</VirtualDirectoryPath> | |
</PropertyGroup> | |
<FileUpdate Files="$(ApplicationHostConfig)" | |
Regex="physicalPath="[^"]+"" | |
ReplacementText="physicalPath="$(VirtualDirectoryPath)"" /> | |
<Touch Files="$(ApplicationHostConfig)" ContinueOnError="True" Time="01/01/2000" /> | |
</Target> | |
</Project> |
Comments
Post a Comment