Posted on

How to Deploy ASP.NET Core Web API on IIS Windows Server

(Tested on windows server 2012r2)

Install the .NET Core Hosting Bundle on Windows Server

The .NET Core Hosting bundle is an installer for the .NET Core Runtime and the ASP.NET Core Module. The bundle allows ASP.NET Core apps to run with IIS.

Current version:.NET Core Hosting Bundle installer (direct download)

(for this test we installed version .Net Core 8 on win 2012r2)

Visual Studio : Publish on Folder

After creating the ASP.NET Core application in Visual Studio, we can use the Visual Studio Publish Tool to deploy and run our app. For this project, choose to publish to a folder. Choose the folder and hit “Finish”.

In the next screen, where you see the settings for this deploy, click on “More Actions” and then on “Edit”.

Select :

  • Deployment Mode : Complete
  • Target Runtime : win-x64 (for our server)
  • File Publish Options : Delete all existing files prior to publish (flagged)
  • Database : Default Connection edit (if yuu need it)

Save this configuration, control it an Publish.

Copy the contents of the folder on the IIS server to the folder dedicated to the new site.

IIS and new site

Create the site on IIS. For the Application Pool you have to use default .NET CLR Version : v4.0.

Open your browser and call up the site. You receive the “page not found” error (404).

Remember that a site that hosts only calls web api. To verify that it works you can use the controller that Visual Studio sets by default when creating a site. Then type:

https://www.mynewapisite.com/WeatherForecast

and you will get a result. The site works!

Posted on

Deploy Xamarin Android App to Google Play Store

Xamarin App basic configuration

Visual Studio Configuration to Debug

AndroidManifest.xml

Open in editor xml (using Visual Studio)

android:debuggable=”true”

Project Propreties

  • Set use Fast Deployment (in the image below is not set)
  • Select apk


Visual Studio Configuration to Play store

AndroidManifest.xml

Open in editor xml (using Visual Studio)

android:debuggable=”false”

Project Propreties

  • Remove use Fast Deployment
  • Select bundle

Posted on

Visual Studio 2022 – programming on Framework 4.5

.NET 4.5 has long been out of support

To use .NET Framework via Visual Studio 2022 you have to download the nunget package :

https://www.nuget.org/packages/microsoft.netframework.referenceassemblies.net45

Rename the extension of the package in .zip to decomprime it.

Put the content in this Folder :

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5

You have to put at the first level the content of the folder

build\\.NETFramework\v4.5

that you can find inside the nunget

Posted on

CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

Compiler Error CS1617

Invalid option ‘option’ for /langversion. Use ‘/langversion:?’ to list supported values.

For example

Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

Solution

Right click on your project and select “Properties” from menu.

Select Build menu and, in the bottom, click on button “Advanced”.

In the next form you don’t have any voice for the field “Language Version”

Select “default”

Done

Posted on

Error publishing Visual Studio Solution on GitHub

On VS 2013 and VS 2015, you should have this error, publishing, first time, your solution on GitHub Repository :

You cannot publish local branch master to the remote repository origin because a branch with the same name already exists there. You might want to rename your local branch and try again.

VS 2013/2015 will initialize the GIT repository when your first commit with sync. So, simple solution is to delete the GIT repository (how to delete) and recreate it without initialize option.

Posted on

Accessing an IISExpress site from another device

You may need to access your developing site with Visual Studio from another device, for example if you want to test if the site is really responsive. You just need to make some changes.

When you open your site by visual studio, the address displayed is

http://localhost:port_number

, where port_number is the port number assigned to the project by Visual studio / IISExpress.

In your project directory you find the .vs directory. Open the file

your_project_folder\.vs\config\applicationhost.config

Here is the bindings tag. In the example you see a specific port number but you have yours.

<bindings>
 <binding protocol="http" bindingInformation="*:60132:localhost" />
</bindings>

Add a line with the ip of your computer. You can add as many as you want.

<bindings>
 <binding protocol="http" bindingInformation="*:60132:localhost" />
<binding protocol="http" bindingInformation="*:60132:192.168.1.142" />
 </bindings>

Open a dos prompt with Administrator privileges and type the command:

netsh http add urlacl url=http://192.168.1.142:60132/ user=everyone

At this point you have to create a firewall rule for your port. From the prompt prompt, launch the command:

netsh advfirewall firewall add rule name="IISExpress_website1" dir=in protocol=tcp localport=60132 profile=private remoteip=localsubnet action=allow

Now you can see the IISExpress website from any networked device using

http://192.168.1.142:60132/

Unfortunately, with this operation you’ll no more control the site using http://localhost:60132 because you need administrator privilege to use the port 60132. So you have two possibilities : first open Visual Studio with Administrator privileges; second, delete this acl:

netsh http delete urlacl url=http://192.168.1.142:60132/
Posted on

ASP.NET MVC: DEPLOY OF A SITE

Visual Studio allows us to publish our web site on a web server in the lan (intranet) or on an external web server, for example hosted on Azure.

In the situation of a server on the lan, you have created, through IIS, a site that resides on a certain directory, empty now, on a web server. Otherwise you have already prepared an external site.

In Visual Studio, in the right panel called “Solution Explorer” we click with the right mouse button on our project and select the “Publish” option. The “Publish” window: there are, on the left, the fourth step to do for publication.

Profile

Go to the drop down menu at the top center and choose “New Custom Profile”. Invent the name of this profile. Once inserted, you will go directly to the next step.

Connection with “Web Deploy”

Publish Metod : choose “Web Deploy”  whether you publish your site on a server on the lan, both in an external server.

Server (web server in lan) : http://myserver

Server (external, es Azure): mysite.azurewebsites.net:443

Site name (web server in lan) : name of the directory in which it is to be the site

Site name (external, es Azure) : es. mysite

User Name e Password (web server in lan) : put a administrator user of the server machine. If the machine is in a domain,  use a local administrator.

User Name e Password (esterno) : ftp user

Destination Url : web site address. es : http://……………..

Settings

In this tab the program reads from we.config the database connection strings. If your target site database is different, you need to specify the right connection. The publication will replace the target strings to the source strings. We will see later that there is a method to insert in the web.config further changes to the web.config of origin.

Preview

Here you can see the files that will be sent to the destination that is the new files or changed since the last submission. And you can publish your site!


web.config configuration

Our destination website may have other special features, specified in web.config, different from the starting site, as well as database connection strings. We can create a specific web.config for each deployment.

Position  the mouse on the project. In the “Properties”, find the directory “PublishProfiles” which contains previously saved data. Here you will find a .pubxml files for each of the deployment that you have created. Go to the file you need, push the right mouse button and select “Add Config Transform”.

If you go in the web.config you will see that there is an additional file named as your deployment. Let’s see some examples of what you can do with the tag that you set within the <configuration>

<connectionStrings>
 <add name="MyDB"
 connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
 xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
 </connectionStrings>

this stringa substitutes (xdt:Transform=”SetAttributes”) the attributes of the tag named  (xdt:Locator=”Match(name)) “MyDB” with these.

<appSettings><add key="myemail" value="info@contoso.com" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/></appSettings>

this stringa substitutes the attributes (xdt:Transform=”SetAttributes”) of the tag with key (xdt:Locator=”Match(key)) “myemai” with these.

<system.net>
 <mailSettings xdt:Transform="Replace">
 <smtp deliveryMethod="Network" ........................
 </smtp>
 </mailSettings>
 </system.net>

This string transform (xdt:Transform=”Replace”) entire tag mailSettings and its content.