2

I am an intermediate WIX user using WIX 3.7 in VS2012. I have multiple webapps solutions.

For each I have a bootstrapper including an MSI project.

I want each installer to conditionally change the port based on what, if anything is already installed in IIS.

In other words: install to port 80 by default or port 81 if 80 is used, or 82 if 81 is used etc.

I have searched for "WIX conditionally change port" and found the following posts

WiX 3.7 IIS Setup
Wix to Install multiple Applications

..but they don't seem to be quite what I need.

Apologies if the answer is staring me in the face and I'm not seeing it.

Thank you.

Community
  • 1
  • 1
Andrew Gray
  • 3,593
  • 3
  • 35
  • 62
  • Another possible heading for this question would be: "How to select the next available 8* port at install time with WIX 3.7?" – Andrew Gray May 30 '13 at 07:45

2 Answers2

0

The obvious solution would be to iterate over all websites and virtual applications on the host and check their port numbers.

Another possibility would be to loop over all ports starting with 80 and checking if it's available. I think the System.Net.NetworkInformation namespace has some useful objects for this kind of stuff, but I don't have much experience with network-related things, so I can't really help you there.

Alternatively, you could run "netstat -a" to get all active connections and parse the results. Redirecting the output to a temp text file might be easier: "netstat -a > c:\temp\netstat.txt". Keep in mind that netstat is somewhat slow.

Either way, I'd keep the port in a property and modify it when you find an available number.

Netfangled
  • 2,071
  • 1
  • 18
  • 28
  • @Andrew From a custom action. There's no built-in functionality for what you're doing. – Netfangled Jun 03 '13 at 13:04
  • If that is so, it seems like a glaring omission to not have a "native" WIX tag to provide what seems (to me at least) a very basic function that every website would need at run time: bind to an unused port. From the department of "Everything is easy if you know how" - What is the most straightforward to achieve this? – Andrew Gray Jun 06 '13 at 06:16
  • @Andrew I would go with the second method (System.Net.NetworkInformation), since all the back-end code is already done. If you really think it should be included in WiX, you could write an extension and submit it to WiX. – Netfangled Jun 06 '13 at 23:47
0

As noted, this functionality does not exist today but the custom actions could be improved to have such a feature. The WiX toolset is Open Source after all.

It'd be a matter of extending the scasched and scaexec DLLs whose source code can be found in the src\ca\serverca folder.

Rob Mensching
  • 33,834
  • 5
  • 90
  • 130