Repository and change control in Visual Studio by Bas Wijdenes

The blog post mainly emphasizes PowerShell. This is because I work with PowerShell myself. You can also use this for other scripts. I myself also have a repository for php.


Repository and change control in Visual Studio the basics.

When I first started with PowerShell I had a folder in OneDrive where I kept a few scripts starting with ‘Login-Office365’. It were pre-scripted scripts for me I could use as a servicedesk engineer. After awhile the scripts in this folder became more and more. I created folders to categorize them.

This worked perfectly until I found Azure Automation, that was magical. I didn’t need to browse through folders and search for my scripts. I used Azure Automation as a ‘database’.

After awhile I had 200+ scripts in Azure Automation and the search function didn’t do much good anymore.

I had files like this:

  • Get-ADUser-Searchbase-OU.ps1
  • Get-ADUser-Export-CSV.ps1
  • Get-ADUser-Set-ADUser.ps1
  • Get-ADUser….
  • Get-ADUser….
  • Etc..

Imagine so many scripts for almost the same function for 80% of the cmdlets in Office 365, Exchange Online, Active Directory, and others.

It became a complete mess. I had to confess to my colleague that it wasn’t working for me anymore. He told and explained me all about Visual Studio Online Repository and I made a tutorial out of it.

Because I think more people should know about this I made a tutorial. I hope you’ll use it and otherwise comment below if you even have a better idea.


PowerShell to Visual Studio Online Repository, the requirements.

There are a few requirements though. They’re simple and you might be using them already.

Requirements


Let’s bring PowerShell to a Visual Studio Online Repository.

Let’s start!
  1. Go to Visualstudio Online
  2. Login to your account > open your profile and start a New Team Project.
    As you can see in the image I already have a Projects. Below the project is a button to create a New Team Project.
Change control Visual Studio Online
Change control Visual Studio Online

Fill in a Project name and leave the rest like it is.
Click Create
(Yes, I know I called mine PHP! Why would I need 2 PowerShell Libraries? ;-))

Repository Visual Studio Online
Repository Visual Studio Online

After you create the new project we can clone it to Visual Studio. There is a button to clone it to Visual Studio. Make sure you’ve installed Visual Studio by now!

PowerShell to Visual Studio Repository
PowerShell to Visual Studio Repository

Your browser will ask you if you  want to open the file format with Visual Studio. That’s up to you to decide, but you cannot clone your repository if you don’t.

Click Open Microsoft Visual…ndler Selector

Change control and Repository Visual Studio Online
Change control and Repository Visual Studio Online

Visual Studio will start and you’ll see your repository to the right.
Before you click Clone lets look at the locations.

  1. Is the location in Visual Studio Online. We cannot change that.
  2. Is the location on your local disk. I changed the location for myself to a OneDrive directory to keep an extra backup. This is up to you.

Click Clone when you’re ready.

PowerShell to Visual Studio Repository
PowerShell to Visual Studio Repository

You’ll see this message:
 The repository was cloned successfully. Create a new project or solution in this repository.

So our clone was successful, great!

We got a repository in Visual Studio Online which is synced locally. What does that mean?

Now we’ve got a repository we can start using the change control Visual Studio offers and keep an online ‘database’ for all our scripts/files/whatever we use on a daily basis.

Now we’ve got a repository in Visual Studio Online we can start using all the features VSO has to offer and keep an online ‘database’ for all our scripts, files, or whatever you want to use it for. I use it on a daily basis.


Change control in Visual Studio.

For me personally this is one of the most important parts. You can change control a repository that’s shared with other users.
At this point we’ll start using Visual Studio Code.

  1. Start visual studio code.
  2. Go to File > Open Folder > Open local folder where you cloned the repository.
  3. Now we’ve got the folder open, we can start creating a new file.
    Click the New file button next to the folder name.

As you can see for yourself, the file became green with a U, but there is also a 1 at the source control (The button that looks like a sharing button).
If you hover your mouse over it, it will say:
Source Control (Ctrl + Shift + G) – 1 pending changes

Change control and Repository Visual Studio Online
Change control and Repository Visual Studio Online

Let’s go to Source Control.

There is a change for the test.php file.
Lets make another change to the file and add some content.
So first I added “Beast!” and after that I added “BlBAlbLAbLABALBALAB”
It will compare the changes:

PowerShell Visual Studio Online
PowerShell Visual Studio Online

Lets say you want to revert the changes, you can right click the file under the folder and click the button Discard Changes.

If the changes are correct you can click the + button. This will Stage the changes. The changes are staged and you’ll be able to commit your changes.
To commit a change you can write down a message of why you commited this change:

Write down your message and press commit:

Commit changes Visual Studio Code
Commit changes Visual Studio Code

This will only commit the changes in your local repository though!
Open the 3 dots, find sync, and sync your repository back to Visual Studio Online.

As you can see all of my scripts are synced back to Visual Studio Online:

Change control and Repository Visual Studio Online
Change control and Repository Visual Studio Online

Get the best out of Visual Studio Code for PowerShelling.

extensions

Let’s start with installing the Extensions necessary to use PowerShell comfortably.
Go to extensions:

Change control and Repository Visual Studio Online
Change control and Repository Visual Studio Online

I’ve got 3 extension installed, but we’re going for two extensions.

  1. PowerShell – This extension is necessary to develop PowerShell scripts so start downloading it.
  2. vscode-icons – This one isn’t necessary, but will show an icon before the scripts and will make your life a lot easier.
Let’s take a look at the theme

Visual Studio Code has quite a few themes, but if you’re a true PowerShell guru there is one theme that is meant for you. One of the themes is named “PowerShell_ISE”

You are only able to load the theme if you have the PowerShell extension installed.
Go to preferences > Color Theme > select the PowerShell_ISE Theme.

Change control and Repository Visual Studio Online
Change control and Repository Visual Studio Online
search function

Another huge perk is the search function. It will not only search for file names, but it will also search in the content. This makes it extremely useful. I can compare scripts quickly and decide which one I want to use.

Here is an example:

last but not least, the graphical user interface

Can’t say much about this one, but I like the GUI so much more than that of PowerShell_ISE, but that is preference of course.

PowerShell Visual Studio Online
PowerShell Visual Studio Online

Recap

That’s it! As I said above, you can also use it for other scripts.

Do you have better ideas, comments, or positive feedback? Then let me know in the comments below.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a Senior Services Engineer. In my spare time I write about the error messages that I encounter during my work. I am currently occupied with Azure infrastructure and automating with PowerShell.

4 thoughts on “Repository and change control in Visual Studio by Bas Wijdenes”

  1. Hi Bas,
    Thanks for our great article.
    I’m considering to use it as well. For the moment I have all my scripts version-controlled in a Github repo which is also very good option.
    Have a nice day
    Gyz

Leave a Reply

Your email address will not be published. Required fields are marked *