IIS Virtual App inner folders duplication

Jul 1, 2016 at 9:52 AM
HI!
I am trying to figure out, how to install website in virtual directory
I've slightly modified IIS sample, so that Files has all content of target folder, including inner folders
 var project =
                new Project("My Product",
                    new Dir(@"%ProgramFiles%\MyCompany",
                        new Dir("MyWebApp",
                            new Dir("AdminWeb2",
                                    new IISVirtualDir
                                    {
                                        Name = "MyWebApp2",
                                        AppName = "Test2",
                                        WebSite = new WebSite("NewSite2", "*:8082") { InstallWebSite = true },
                                        WebAppPool = new WebAppPool("MyWebApp2", "Identity=applicationPoolIdentity")
                                    },
                                    new Files(@"MyWebApp\AdminWeb2\*.*")))));
The problem is that after installation inner folders are duplicated both in Website and Virtual app:
Image
I expect them to be only in Virtual app

Can you please help me to resolve this problem?
Thx
Coordinator
Jul 4, 2016 at 1:36 AM
Hi there,

Thank you for such a good test case and problem description. It was very easy to reproduce the problem.

To be honest I am puzzled about this one. I thought that there is some defect that leads to the duplicated WiX entry generated by Wix# and fixing it would be straight forward. But unfortunately it's not the case. Wix# produces no duplication. This is what it yields:
<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder" Name="ProgramFilesFolder">
    <Directory Id="ProgramFilesFolder.MyCompany" Name="MyCompany">
      <Directory Id="ProgramFilesFolder.MyCompany.MyWebApp" Name="MyWebApp">
        <Directory Id="INSTALLDIR" Name="AdminWeb2">

          <Component Id="Component.Default.aspx" Guid="6fe30b47-2577-43ad-9095-186184d65318">
            <File Id="Default.aspx" Source="MyWebApp\AdminWeb2\Default.aspx" />
          </Component>

          <Component Id="Component.INSTALLDIR.VirtDir" Guid="6fe30b47-2577-43ad-9095-1861039518d9" KeyPath="yes">
            <WebVirtualDir Id="VirtDir" Alias="MyWebApp2" Directory="INSTALLDIR" WebSite="WebSite" xmlns="http://schemas.microsoft.com/wix/IIsExtension">
              <WebApplication Id="Test2WebApplication" Name="Test2" WebAppPool="MyWebApp2_AppPool" />
            </WebVirtualDir>

            <WebSite Id="WebSite" Description="NewSite2" Directory="INSTALLDIR" xmlns="http://schemas.microsoft.com/wix/IIsExtension">
              <WebAddress Id="WebSite_Address1" IP="*" Port="8082" />
            </WebSite>

            <WebAppPool Id="MyWebApp2_AppPool" Name="MyWebApp2" Identity="applicationPoolIdentity" xmlns="http://schemas.microsoft.com/wix/IIsExtension" />
            <RemoveFolder Id="INSTALLDIR" On="uninstall" />
          </Component>

          <Directory Id="INSTALLDIR.inner_folder" Name="inner_folder">

            <Component Id="Component.New_Text_Document.txt" Guid="6fe30b47-2577-43ad-9095-1861cbc8de3b">
              <File Id="New_Text_Document.txt" Source="MyWebApp\AdminWeb2\inner_folder\New Text Document.txt" />
            </Component>

          </Directory>
        </Directory>
      </Directory>
    </Directory>
  </Directory>
</Directory>
I do not see anything wrong with the XML above. Though IIS part of WiX can be quite tricky to deal with.

Thus I cannot offer you any advise. I can only see these possible explanations:
  1. Wix# produces valid XML but it's is some how logically incorrect.
  2. XML is perfectly fine it's just MSI playing up at runtime and creates the duplication.
  3. Everything works as expected. It's just IIS dashboard displays the configuration in an unexpected way. Possible but unlikely...
Unfortunately I can only address #1, the others are not related to Wix#. But as I mentioned I am not sure what are the possible changed to the WiX XML that would remove the duplication.

Sorry mate, I know it's not the answer you were looking for...
Jul 5, 2016 at 12:08 PM
Edited Jul 5, 2016 at 12:08 PM
Oleg, thanks for your answer.
After some investigation I ended up with thoughts that everything works as expected.

There is no possibility in Wix# to specify a physical path (folder) for website, therefore both IIS virtual dir, and its created parent website share one physical path.
In this way, while sharing one physical path, that is okay, that we see same content in WebSite node and WebApp node.

Can I suggest to add possibility to specify Website physical path explicitly?

That would be exactly tha same approach as with 'Default web Site'. Is targets %wwwroot$ directory, while all its WebApplications can have different paths.

Thanks for your time!
Coordinator
Jul 6, 2016 at 12:56 AM
> Can I suggest to add possibility to specify Website physical path explicitly?
Unfortunately this is what exactly the problem. I cannot add it as WiX's WebSite element doesn't support this attribute. That's why I started suspecting that "everything works as expected". It's a WiX design constrain but not Wix# one.

Of course, quite a few times in order to overcome WiX API clumsiness I had to created Wix# decorations (syntactic sugar). But it's only possible for the situations involving simple WiX elements relationships. IIS is not one of them. If I have a WiX solution then I can come up with the way of encoding it in Wix# but in this case I don't see any WiX work around.
Oct 19, 2016 at 2:14 PM
hi guys i started learning Wix# like yesterday.
I faced the duplication issue and it got fixed when i changed
InstallWebSite = False

But i am facing some other issue while trying to install 2 websites.
the webapplication id is getting repeated for both the application and i am not able to figure out how to change it.

 <Component Id="Component.BackofficeServer.VirtDir" Guid="859174dc-646e-4717-b542-2e3f16d3ffa7" KeyPath="yes">
          <WebVirtualDir Id="BackofficeServer" Alias="BackofficeServer" Directory="BackofficeServer" WebSite="BackofficeServer" xmlns="http://schemas.microsoft.com/wix/IIsExtension">
            <WebApplication Id="MyWebAppWebApplication" Name="MyWebApp" WebAppPool="BackofficeServer_AppPool" />
          </WebVirtualDir>
<Component Id="Component.Backoffice.VirtDir" Guid="859174dc-646e-4717-b542-2e3f1ff05680" KeyPath="yes">
            <WebVirtualDir Id="Backoffice" Alias="Backoffice" Directory="Backoffice" WebSite="Backoffice" xmlns="http://schemas.microsoft.com/wix/IIsExtension">
              <WebApplication Id="MyWebAppWebApplication" Name="MyWebApp" WebAppPool="Backoffice_AppPool" />
            </WebVirtualDir>
Below is the part of the code i have written so far.
When i do it for one website everything works fine.
new IISVirtualDir
                                       {
                                           Name = "BackofficeServer",
                                           Id = "BackofficeServer",
                                           WebSite = new WebSite
                                           {
                                               Id= "BackofficeServer",
                                               Name= "BackofficeServer",
                                               InstallWebSite = false,
                                               Description = "BackofficeServer",
                                               Addresses = new[]
                                                {
                                                    new WebSite.WebAddress
                                                    {
                                                        Attributes = new Attributes()
                                                        {
                                                            { "IP", "*" },
                                                            { "Port", "80" }
                                                        }
                                                    }
                                               }
                                           },
                                           WebAppPool = new WebAppPool("DefaultAppPool"),
                                       },
new IISVirtualDir
                            {
                                Name = "Backoffice",
                                Id = "Backoffice",
                                WebSite = new WebSite(new Id("Backoffice"), "Backoffice")
                                {
                                    InstallWebSite = false,
                                    Addresses = new[]
                                                    {
                                                        new WebSite.WebAddress
                                                        {
                                                            Attributes = new Attributes()
                                                            {
                                                                { "IP", "*" },
                                                                { "Port", "80" }
                                                            }
                                                        }
                                                   }
                                },
                            WebAppPool = new WebAppPool("DefaultAppPool"),
                        }
Can somebody help me this this one?
Coordinator
Oct 22, 2016 at 6:27 AM
Sorry, I didn't catch your post earlier.

The easiest way to fixed undesired ID allocation is to use explicit IDs. Though in your case it is problematic as WebApplication element mapped indirectly. Thus the only choice you have is to replace the attribute directly (after the allocation). Have a look at InjectXML sample. It will be something like this:
project.WixSourceGenerated += doc => doc.Root.FindAll("WebApplication")
                                             .First()
                                             .SetAttribute("Id", "NewIdValue");
Also you may find IIS_XMLInjection sample very useful as it shows some raw XML manipulation techniques.

Unfortunately my knowledge of IIS is rather limited. Thus it's hard for me to judge but if you feel that your use case is reasonable common, log a feature request and I will expose WebApplication.Id directly to the Wix# interface.
Oct 22, 2016 at 7:51 AM
thanks a ton oleg_s
I was giving up on Wix# and about to do it in WIX only.

But let's give it a try again , i'll rather comfortable writing lambda expressions instead of pure xml :P

Also thanks for heads up on IIS_XMLInjection , i think will help me manage my connection strings.
Nov 29, 2016 at 1:14 PM
Hi,

My MSI installs 2 websites and 1 win service (i.e 3 directories) and everything is installing to c:\programfiles(x86)\CompanyName\ProductName
I am successfully able to add given two websites in IIS as separate webapplications.

now how to install ProductName as a website and convert 2 of the directories inside to web-application (similar to manually doing it in IIS)
Dec 13, 2016 at 2:14 PM
DEMETRON wrote:
Hi,

My MSI installs 2 websites and 1 win service (i.e 3 directories) and everything is installing to c:\programfiles(x86)\CompanyName\ProductName
I am successfully able to add given two websites in IIS as separate webapplications.

now how to install ProductName as a website and convert 2 of the directories inside to web-application (similar to manually doing it in IIS)
Guys i still can't figure this out any help would be great.
Coordinator
Dec 13, 2016 at 10:50 PM
Edited Dec 15, 2016 at 2:59 AM
This is truly a WiX challenge not a Wix# one. If you have a WiX code solution then I would be happy to look at translating it into Wix# code. But otherwise I am limited in my options. I am no expert in WiX-for-IIS.

In my opinion IIS support is one of the most over complicated (and sometimes illogically designed) areas of MSI/WiX. And that is why I couldn't provide any serious adapter-API layer for simplifying it. Thus Wix#-for-IIS is (not 100% but) almost 1-to-1 follows WiX-for-IIS API model.
Dec 14, 2016 at 3:18 AM
oleg_s wrote:
This is truly a WiX challenge not a Wix# one. If you have a WiX code solution then I would be happy to look at translating it into Wix# code. But otherwise I am limited in my options. I am no expert in WiX-for-IIS.

In my opinion IIS support is one of the most over complicated (and sometimes illogically designed) areas of MSI/WiX. And that is why I couldn't provide any serious adapter-API layer for simplifying it. This Wix#-for-IIS is (not 100% but) almost 1-to-1 follows WiX-for-IIS API model.
thanks oleg_s problem is i started with Wix# only and have no experience with wix let me try to find if wix has a solution for this then we can think of doing the same in wix#.