CI/CD avec Visual Studio et Azure

Je pars sur une application .NET (ASP.NET Core) dĂ©ployĂ©e sur Azure App Service, avec Azure DevOps pour le pipeline. Si ta stack est diffĂ©rente (conteneurs, Functions, AKS), l’approche reste la mĂȘme, seules les tĂąches de dĂ©ploiement changent.

Architecture

Visual Studio → Azure Repos (ou GitHub) → Azure Pipelines
│
Build + Tests → Artefact → Staging (slot) → Approbation → Swap vers Production
│
Application Insights

Étape 1 : PrĂ©parer le projet dans Visual Studio

  1. Ouvre ta solution et ajoute un projet de tests (xUnit ou NUnit). Vérifie que tout passe dans Test Explorer.
  2. Ajoute un endpoint de santé, utile pour les smoke tests : builder.Services.AddHealthChecks();// ...app.MapHealthChecks("/health");
  3. CrĂ©e le dĂ©pĂŽt Git : menu Git → Create Git Repository, puis choisis Azure DevOps ou GitHub et pousse le code.

Étape 2 : CrĂ©er les ressources Azure

Avec Azure CLI (ou le portail) :

az login
az group create -n rg-monapp -l canadaeast
az appservice plan create -n plan-monapp -g rg-monapp --sku S1
az webapp create -n monapp-web -g rg-monapp -p plan-monapp --runtime "dotnet:8"
az webapp deployment slot create -n monapp-web -g rg-monapp --slot staging

Points importants :

  • Les slots de dĂ©ploiement demandent un plan Standard (S1) ou supĂ©rieur.
  • Adapte le nom monapp-web, qui doit ĂȘtre unique mondialement. VĂ©rifie les runtimes disponibles avec az webapp list-runtimes.
  • Ajoute Application Insights (créé avec le Web App ou sĂ©parĂ©ment) pour le monitoring.

Étape 3 : Configurer Azure DevOps

  1. Crée un projet sur dev.azure.com.
  2. Project Settings → Service connections → New → Azure Resource Manager. Choisis l’authentification Workload identity federation (recommandĂ©e, sans secret Ă  gĂ©rer) et limite la portĂ©e au groupe de ressources rg-monapp. Nomme-la sc-azure-prod.
  3. Pipelines → Environments : crĂ©e staging et production.
  4. Sur production, ajoute une Approval check (toi ou ton équipe).

À noter : les agents hĂ©bergĂ©s par Microsoft peuvent nĂ©cessiter une demande de parallĂ©lisme gratuit sur les nouvelles organisations. VĂ©rifie ce point dans les paramĂštres de ton organisation si le pipeline reste en attente.

Étape 4 : Le pipeline azure-pipelines.yml

À la racine du dĂ©pĂŽt :

trigger:
branches:
include: [main]
pr:
branches:
include: [main]
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
azureSubscription: 'sc-azure-prod'
webAppName: 'monapp-web'
resourceGroup: 'rg-monapp'
stages:
# ---------- CI ----------
- stage: Build
jobs:
- job: BuildTest
steps:
- task: UseDotNet@2
inputs:
packageType: sdk
version: '8.x'
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: restore
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) --no-restore'
- task: DotNetCoreCLI@2
displayName: Tests unitaires
inputs:
command: test
projects: '**/*Tests.csproj'
arguments: '--configuration $(buildConfiguration) --no-build --collect:"XPlat Code Coverage"'
- task: DotNetCoreCLI@2
displayName: Publish
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- publish: $(Build.ArtifactStagingDirectory)
artifact: drop
# ---------- CD : Staging ----------
- stage: DeployStaging
dependsOn: Build
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs:
- deployment: Staging
environment: staging
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
displayName: Déploiement dans le slot staging
inputs:
azureSubscription: $(azureSubscription)
appType: webApp
appName: $(webAppName)
deployToSlotOrASE: true
resourceGroupName: $(resourceGroup)
slotName: staging
package: $(Pipeline.Workspace)/drop/**/*.zip
- script: |
sleep 20
curl --fail --retry 5 --retry-delay 10 https://$(webAppName)-staging.azurewebsites.net/health
displayName: Smoke test
# ---------- CD : Production ----------
- stage: DeployProd
dependsOn: DeployStaging
jobs:
- deployment: Production
environment: production # déclenche l'approbation manuelle
strategy:
runOnce:
deploy:
steps:
- task: AzureAppServiceManage@0
displayName: Swap staging vers production
inputs:
azureSubscription: $(azureSubscription)
Action: 'Swap Slots'
WebAppName: $(webAppName)
ResourceGroupName: $(resourceGroup)
SourceSlot: staging
SwapWithProduction: true

Puis dans Azure DevOps : Pipelines → New pipeline → Azure Repos Git → Existing YAML file.

Étape 5 : ProtĂ©ger la branche main

Repos → Branches → main → Branch policies :

  • Revue de code obligatoire (1 reviewer minimum).
  • Build validation : le pipeline doit rĂ©ussir avant de pouvoir fusionner une PR.
  • RĂ©solution des commentaires obligatoire.

Résultat : les PR lancent le build et les tests (étape CI uniquement), et seul un merge sur main déclenche le déploiement.

Étape 6 : GĂ©rer les secrets et la configuration

  • Azure Key Vault pour les mots de passe, chaĂźnes de connexion et clĂ©s d’API. Donne Ă  l’App Service une Managed Identity et rĂ©fĂ©rence les secrets avec @Microsoft.KeyVault(SecretUri=...) dans les paramĂštres de l’application.
  • Utilise des paramĂštres de slot (« Deployment slot setting ») pour les valeurs propres Ă  chaque environnement.
  • Ne mets jamais de secrets dans le dĂ©pĂŽt ni dans le YAML.

Étape 7 : Monitoring et retour arriùre

  • Application Insights pour les requĂȘtes, erreurs, dĂ©pendances et performances. Configure des alertes (taux d’erreur, temps de rĂ©ponse).
  • Rollback instantanĂ© : refais un swap des slots. L’ancienne version est toujours dans le slot staging aprĂšs le swap.

Alternative : le raccourci depuis Visual Studio

Dans Visual Studio, clic droit sur le projet → Publish → Azure → Azure App Service. L’assistant peut proposer de gĂ©nĂ©rer un workflow GitHub Actions (CI/CD) avec les identifiants Azure dĂ©jĂ  configurĂ©s. C’est trĂšs rapide pour dĂ©marrer, mais moins complet qu’un pipeline en plusieurs Ă©tapes avec approbations. Garde-le pour un prototype, et utilise le pipeline YAML ci-dessus pour un projet sĂ©rieux.

Évolutions possibles

  • Infrastructure as Code : dĂ©crire les ressources Azure avec Bicep ou Terraform plutĂŽt qu’avec des commandes manuelles.
  • Scans de sĂ©curitĂ© : Defender for DevOps, CodeQL, scan de dĂ©pendances.
  • Conteneurs : build d’image Docker, push vers Azure Container Registry, dĂ©ploiement sur App Service for Containers ou Azure Container Apps.
  • DĂ©ploiement canary : le « Testing in production » des slots permet de router un pourcentage du trafic vers staging avant le swap.

Posted in Informatique | Leave a comment

MVVM Tutorial From Start to Finish

MVVM Tutorial From Start to Finish

Posted in CSharp | Tagged , | Leave a comment

Environment Variables

Environment Variables

Source: Microsoft
Variable Type Description
%ALLUSERSPROFILE% Local Returns the location of the All Users Profile.
%APPDATA% Local Returns the location where applications store data by default.
%CD% Local Returns the current directory string.
%CMDCMDLINE% Local Returns the exact command line used to start the current Cmd.exe.
%CMDEXTVERSION% System Returns the version number of the current Command Processor Extensions.
%COMPUTERNAME% System Returns the name of the computer.
%COMSPEC% System Returns the exact path to the command shell executable.
%DATE% System Returns the current date. Uses the same format as the date /tcommand. Generated by Cmd.exe.
%ERRORLEVEL% System Returns the error code of the most recently used command. A non zero value usually indicates an error.
%HOMEDRIVE% System Returns which local workstation drive letter is connected to the user’s home directory. Set based on the value of the home directory. The user’s home directory is specified in Local Users and Groups.
%HOMEPATH% System Returns the full path of the user’s home directory. Set based on the value of the home directory. The user’s home directory is specified in Local Users and Groups.
%HOMESHARE% System Returns the network path to the user’s shared home directory. Set based on the value of the home directory. The user’s home directory is specified in Local Users and Groups.
%LOGONSEVER% Local Returns the name of the domain controller that validated the current logon session.
%NUMBER_OF_PROCESSORS% System Specifies the number of processors installed on the computer.
%OS% System Returns the operating system name. Windows 2000 displays the operating system as Windows_NT.
%PATH% System Specifies the search path for executable files.
%PATHEXT% System Returns a list of the file extensions that the operating system considers to be executable.
%PROCESSOR_ARCHITECTURE% System Returns the chip architecture of the processor. Values: x86, IA64.
%PROCESSOR_IDENTFIER% System Returns a description of the processor.
%PROCESSOR_LEVEL% System Returns the model number of the processor installed on the computer.
%PROCESSOR_REVISION% System Returns the revision number of the processor.
%PROMPT% Local Returns the command prompt settings for the current interpreter. Generated by Cmd.exe.
%RANDOM% System Returns a random decimal number between 0 and 32767. Generated by Cmd.exe.
%SYSTEMDRIVE% System Returns the drive containing the Windows XP root directory (that is, the system root).
%SYSTEMROOT% System Returns the location of the Windows XP root directory.
%TEMP% and %TMP% System and User Returns the default temporary directories that are used by applications available to users who are currently logged on. Some applications require TEMP and others require TMP.
%TIME% System Returns the current time. Uses the same format as the time /tcommand. Generated by Cmd.exe.
%USERDOMAIN% Local Returns the name of the domain that contains the user’s account.
%USERNAME% Local Returns the name of the user who is currently logged on.
%USERPROFILE% Local Returns the location of the profile for the current user.
%WINDIR% System Returns the location of the operating system directory.
http://libertyboy.free.fr/computing/reference/envariables/
Posted in Informatique | Tagged | Leave a comment

Excel specifications and limits

http://office.microsoft.com/en-001/excel-help/excel-specifications-and-limits-HP010342495.aspx

Posted in Excel | Tagged , | Leave a comment

Send Keys

Send / SendRaw / SendInput / SendPlay / SendEvent: Send Keys & Clicks
http://www.autohotkey.com/docs/commands/Send.htm

Posted in Informatique | Leave a comment

Data Type Conversion (Database Engine)

Implicit and Explicit Conversion:

Implicit and Explicit Conversion

Implicit and Explicit Conversion

Posted in SQL | Leave a comment

Microsoft SQL Server Data Tools

…provides an integrated environment for database developers to carry out all their database design work for any SQL Server platform (both on and off premise) within Visual Studio. Database developers can use the SQL Server Object Explorer in VS to easily create or edit database objects and data, or execute queries

Microsoft SQL Server Data Tools

Posted in Informatique, SQL | Leave a comment

SQL Server Data Tools – Business Intelligence

Download File

Install SQL Server Data Tools – Business Intelligence for Visual Studio 2012
To install SQL Server Data Tools – Business Intelligence for Visual Studio 2012

  1. Run SSDTBI_VS2012_x86_ENU.exe to begin installation.
  2. In SQL Server 2012 Setup, on the License Terms page, if you agree to the Microsoft Software License Terms, select I accept the license terms, optionally select Send feature usage data to Microsoft, and then click Next.
  3. On the Installation Type page, verify Perform a new installation of SQL Server 2012 is selected, and then click Next.  Note: Setup will not install a new instance of SQL Server 2012 Server, but will install new SQL Server Features, including SQL Server Data Tools- Business Intelligence for Visual Studio 2012, which you will select on the next Feature Selection page.
  4. On the Feature Selection page, click SQL Server Data Tools – Business Intelligence for Visual Studio 2012, and then click Next.
  5.  On the Error Reporting page, optionally select Send Windows and SQL Server Error Reports to Microsoft or your corporate report server, and then click Next.
Posted in SQL | Leave a comment

IDisposable interface

public class MyClass : IDisposable
{
    private bool disposed;

    /// <summary>
    /// Construction
    /// </summary>
    public MyClass()
    {
    }

    /// <summary>
    /// Destructor
    /// </summary>
    ~MyClass()
    {
        this.Dispose(false);
    }

    /// <summary>
    /// The dispose method that implements IDisposable.
    /// </summary>
    public void Dispose()
    {
        this.Dispose(true);
        GC.SuppressFinalize(this);
    }

    /// <summary>
    /// The virtual dispose method that allows
    /// classes inherithed from this one to dispose their resources.
    /// </summary>
    /// <param name="disposing"></param>
    protected virtual void Dispose(bool disposing)
    {
        if (!disposed)
        {
            if (disposing)
            {
                // Dispose managed resources here.
            }

            // Dispose unmanaged resources here.
        }

        disposed = true;
    }
}

 

Posted in CSharp | Tagged | Leave a comment