Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update IIS Express port in Visual Studio 2012 when creating project template

I know the title seems a bit misleading but the problem is fairly simple.

I just created a new WebApplication project in Visual Studio 2012 Express for Web, added a couple of extra files and exported the project as a new template. Everything seemed to be working fine until I started debugging a new project instance from this template. When I opened the properties window for the project instance I noticed that the "Project URL" setting under "Web" pointed to http://localhost:50637 where the port number is the same as the project I used to create the template from. Obviously I want the new project instance to have its own port and I can easily just assign a new one. But my question is whether it is possible for Visual Studio to do automatically when creating new project instances? I imagine I would have to configure the project properties for the template project some how...

like image 238
Stig Perez Avatar asked Mar 31 '13 15:03

Stig Perez


People also ask

How do I change the port number for IIS Express?

In Solution Explorer, right-click the name of the web application and select Properties. Click the Web tab. In the Servers section, under dropdown selection for IIS Express, change the port number in the Project URL box. To the right of the Project URL box, click Create Virtual Directory, and then click OK.

What port is IIS Express running on?

iisexpress /path:c:\myapp\ /port:80 This command runs the site from c:\myapp folder over port 80. Run your site using one of the following: Use /config to run a site from a configuration file.

How can I change port number in asp net?

In Solution Explorer, click the name of the application. In the Properties pane, click the down-arrow beside Use dynamic ports and select False from the dropdown list. This will enable editing of the Port number property. In the Properties pane, click the text box beside Port number and type in a port number.


2 Answers

After you export the project as a new template, unzip the exported zip file. This is so that you can edit the .csproj file for the website. Open up the .csproj file in notepad and edit the following section:

<ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>True</UseIIS>
          <AutoAssignPort>True</AutoAssignPort>
          <DevelopmentServerPort>0</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          ***<IISUrl></IISUrl>***
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>False</UseCustomServer>
          <CustomServerUrl>
          </CustomServerUrl>
          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>

Where the <IISUrl>http://localhost:59344/</IISUrl> is, just remove the http://localhost:59344/ url so that it is blank. Then rezip up the folder and install the extension.

A new port number will then be created automatically when the project is created.

like image 117
Sylvia Avatar answered Oct 03 '22 06:10

Sylvia


In Visual Studio 2019, you need to remove the launchSettings.json from the Properties directory so the visual studio can create the file automatically during the project creation.

Steps:

1- Create a web project

2- Delete the launchSettings.json from the Properties directory.

3- In the Visual Studio 2019, click on the project tab, then click on the export template

Now you can create a new web project by finding your project template, and the VS will automatically create the launchSettings.json file with a random web port.

like image 37
Mohammad Karimi Avatar answered Oct 03 '22 06:10

Mohammad Karimi