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

Accedere ad un sito su IISExpress da un altro device

Potreste avere la necessità di accedere al vostro sito in sviluppo con Visual Studio da un altro device: per esempio se volete testare se il sito è realmente responsive.Bisogna fare solo alcune modifiche.

Quando aprite il vostro sito da visual studio viene visualizzato l’indirizzo

http://localhost:port_number

, dove port_number è il numero di porta assegnato al progetto da Visual studio /IISExpress.

Nella vostra directory di progetto trovate la directory .vs. Aprite il file

your_project_folder\.vs\config\applicationhost.config

Qui trovate il tag bindings. Nell’esempio vedete uno specifico numero di porta ma voi avrete il vostro.

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

Aggiungete una riga con l’ip del vostro computer. Potete aggiungerne quante ne volete.

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

Aprite un prompt di dos con privilegi di Amministratore e digitate il comando :

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

A questo punto dovete creare una regola sul firewall per la vostra porta.Sempre dal prompt di dos lanciate il comando :

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

Ora potete raggiungere il sito web di IISExpress da qualsiasi device in rete utilizzando

http://192.168.1.142:60132/
Posted on

ASP.NET MVC: PUBBLICAZIONE DI UN SITO

Visual Studio ci consente di pubblicare il nostro sito web su un web server interno (intranet) o su un web server esterno, per esempio ospitato su Azure.

Nel caso di un server in lan, su un web server avete creato tramite IIS un sito che risiede su una certa directory per adesso vuota. Altrimenti avete già pronto un sito esterno.

In Visual Studio, nel pannello a destra chiamato “Solution Explorer” facciamo click con il tasto destro del mouse sul nostro progetto e selezioniamo l’opzione “Publish“. Si apre la finestra “Publish” che riporta a sinistra i 4 step da fare per la pubblicazione.

Profile

Andate sul menu a tendina in alto al centro  e scegliete “New Custom Profile”. Inventatevi il nome di questo profilo. Una volta inserito, passerete direttamente allo step successivo.

Connection con il metodo “Web Deploy”

Publish Metod : scegliere Web Deploy sia che si pubblichi il sito in un server in lan, sia in un server esterno.

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

Server (esterno, per esempio Azure): mysite.azurewebsites.net:443

Site name (web server in lan) : nome della directory in cui deve risiedere il sito

Site name (esterno, per esempio Azure) : nome che avete dato al sito (mysite)

User Name e Password (web server in lan) : mettere uno username amministratore della macchina server. Se la macchina è in dominio usare un Amministratore locale.

User Name e Password (esterno) : ftp user

Destination Url : indirizzo del sito web. es : http://……………..

Settings

In questa tab il programma legge dal we.config le stringhe di connessione al database. Se nel vostro sito di destinazione il database è diverso, dovete specificare la giusta connessione. La pubblicazione sostituira le stringhe di destinazione alle stringhe di origine. Vedremo in seguito che esiste un metodo per inserire nel web.config ulteriori variazioni rispetto al web.config di origine.

Preview

Qui potete vedere i file che saranno inviati alla destinazione cioè i nuovi o  i modificati dopo l’ultimo invio. E potete pubblicare!


Configurazione del web.config

Il nostro sito web di destinazione può avere altre caratteristiche particolari, specificate nel web.config, diverse dal sito di partenza, oltre alle stringhe di connessione al database.
Ci possiamo creare un web.config specifico per ogni deploy.

Andate sul progetto. Nelle “Proprietà”, trovate la directory “PublishProfiles” che contiene i dati salvati precedentemente. Trovate un file .pubxml per ognuno dei deploy che avete creato. Andate su file che vi interessa, spingete il tasto destro del mouse e selezionate “Add Config Transform”.

Se andate nel web.config vedrete che esiste un file aggiuntivo che si chiama come il vostro deploy.  Vediamo alcuni esempi di quello che potete fare con tag che inserirete all’interno di <configuration>

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

Questa stringa sostituisce (xdt:Transform=”SetAttributes”) gli attributi del tag che si chiama (xdt:Locator=”Match(name)) “MyDB” con quelli che trova qui.

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

Questa stringa sostituisce gli attributi (xdt:Transform=”SetAttributes”) del tag che ha come key (xdt:Locator=”Match(key)) “myemai” con quelli che trova qui.

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

Questa stringa trasforma (xdt:Transform=”Replace”) tutto il tag mailSettings ed il suo contenuto.