How to use an Azure DevOps NuGet feed in Visual Studio Code and Visual Studio

If you want to use NuGet or npm packages from an Azure DevOps pipeline in Visual Studio Code, you can following these steps:

Prerequisites

You must first install the “Microsoft Azure Artifacts Credential Provider”.

https://github.com/Microsoft/artifacts-credprovider

On a Windows machine I installed it by:
– creating a file: C:\Temp\installcredprovider.ps1″.
– copying the code from “https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1” to it
– executed the file in a PowerShell prompt:

Set-Location "C:\Temp"
.\installcredprovider.ps1

Project

Add the feed to NuGet configuration

Add feed to your NuGet configuration by executing:

nuget.exe sources Add -Name “spike-feed” -Source “https://roelvanlisdonk.pkgs.visualstudio.com/_packaging/spike-feed/nuget/v3/index.json”

NOTE: use the exact line as found under > Artifacts > Connect to feed button:
In mine case: nuget.exe sources Add -Name “spike-feed” -Source “https://roelvanlisdonk.pkgs.visualstudio.com/_packaging/spike-feed/nuget/v3/index.json”

The name should really be the name of the feed, not some custom name.

Feed

Run dotnet restore once with –interactive to authenticate against the Azure DevOps feed

We have to execute dotnet restore with –interactive once, to authenticate against the Azure DevOps feed.

dotnet restore --interactive

After that you can use dotnet restore without manual authentication.
Now if you open the .NET Core solution in Visual Studio it will also work and you don’t have to do anything.

Angular – Test error – No base href set

When running a ng test with Angular v6.2.9 cli, I was getting the error:

Error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.

This was fixed by adding the RouterTestingModule tot the TestBed TestingModule:

import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { AppModule } from './app.module';
import { RouterTestingModule } from '@angular/router/testing';

describe('AppComponent', () => {
    beforeEach(async(() => {
        TestBed.configureTestingModule({
        declarations: [],
        imports: [
        AppModule,
        RouterTestingModule
        ]
    }).compileComponents();
}));

it('should create the app', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
    });
});

Change linked service / dataset connection string in an Azure Data Factory with PowerShell after deployment

When you connect an Azure Data Factory to GIT it will create json files per linked service, but the json file will contain some part of the connection string. If you want to change the connection string after deployment, you can use the following script.


# This script assumes the linked service json files can be found in the folder .\linkedService, relative to the location of this script.

param (
    [Parameter(Mandatory=$True)]
    [string]
    $ResourceGroupName,

    [Parameter(Mandatory=$True)]
    [string]
    $DataFactoryName,

    [Parameter(Mandatory=$True)]
    [string]
    $Find,

    [Parameter(Mandatory=$True)]
    [string]
    $Replace
)

$root = $PSScriptRoot
$scriptName = $MyInvocation.MyCommand.Name
Write-Host "$scriptName - start"

Write-Host "Get all linked service json file names"
$linkedServicesPath = "$root\linkedService"
$names = Get-ChildItem -Path "$linkedServicesPath" -Name

Write-Host "Loop file names"
foreach ($name in $names)
{
    Write-Host "Find the text [$Find] and replace with [$Replace] in the file [$path]."
    $path = [System.IO.Path]::Combine($linkedServicesPath, $name)
    (Get-Content -Path "$path" -Raw).Replace("$Find", "$Replace") | Set-Content -Path "$path"

    $linkedServiceName = [System.IO.Path]::GetFileNameWithoutExtension($name)
    Write-Host "Update the linked service [$linkedServiceName] on ResourceGroupName [$ResourceGroupName] in DataFactoryName [$DataFactoryName] by using File [$path] on Azure.."
    Set-AzureRmDataFactoryV2LinkedService -ResourceGroupName "$ResourceGroupName" -DataFactoryName "$DataFactoryName" -Name "$linkedServiceName" -File "$path"
}

Write-Host "$scriptName - end"

Example linked service json file:
Note: The sql server database connections, that I use, use MSI for authentication.

{
	"name": "MySqlDb1LinkedService",
	"type": "Microsoft.DataFactory/factories/linkedservices",
	"properties": {
		"type": "AzureSqlDatabase",
		"typeProperties": {
			"connectionString": "Integrated Security=False;Encrypt=True;Connection Timeout=30;Data Source=my-sql-server-v1.database.windows.net;Initial Catalog=MySqlDb1"
		}
	}
}

Select views that don’t reference other views in SQL Server

 

 

— Select views that don’t reference other views.

select

        s.[name]

,       v.[name]

from    sys.views v

join    sys.schemas s on v.schema_id = s.schema_id

where   v.object_id not
in (

    select distinct

                r.referenced_id

    from        sys.dm_sql_referenced_entities (s.[name] + ‘.’ + v.[name], ‘OBJECT’) r

    join        sys.objects o on r.referenced_id = o.object_id

    where       o.[type] = ‘V’

)

order by    s.[name], v.[name]

 

 

Select views that reference other views in SQL Server

 

— Select views that reference other views.

select distinct

            s.[name]

,           v.[name]

,           r.referenced_schema_name

,           r.referenced_entity_name

from        sys.views v

join        sys.schemas s on v.schema_id = s.schema_id

cross
apply sys.dm_sql_referenced_entities (s.[name] + ‘.’ + v.[name], ‘OBJECT’) r

join        sys.objects o on r.referenced_id = o.object_id

where       o.[type] = ‘V’

order by    s.[name], v.[name]