Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Thursday, August 25, 2016

GIT 101 in Visual Studio Team Services (VSTS)

Hi All,

I have been working with multiple developers on sharing project code using git. I found out that git is new to a lot of developers who have been using Visual Studio Team Foundation Server (TFS), Visual Studio Online (VSO aka VSTS now), or any other centralized source control system.

What is the difference between TFS/VSO/VSTS versus Git?

If you have been using TFS, VSTS or VSO, those all fall under Team foundation Version Control (TFVC) which is a centralized source control system.

While git, is a distributed source control system (DVCS). which means: you have a local and remote code repositories. you can commit your code to you local repo but not remote repo (unless you want to). Also, you can share your code to the remote repo so other team members can get these changes.
This is a fundamental concept to understand when working with git. git is distributed, contains local and remote repos & works offline and it is a great way to enable collaborations among developers.

**Popular git platforms: GitHub, VSTS, Bitbucket, GitLab, RhodeCode and others.

This article is focusing on managing multiple developers code working in a team & what is the git best practices around that, This also applies to any other git platform. For the sake of simplicity, This article will be focusing on using Git in VSTS.

Basic terminology and keywords to know when working with Git:

1) A branch: In Git, every developer should have his own branch. you write code and commit your changes into your local branch. To sync with other developers, get latest from the master branch and merge it into yours so you make sure everything is compiling & working before creating a new pull request to the master branch (by merging back your code into master).

2) Fetch: It download changes to your local branch from the remote branch. Fetch downloads these commits and adds them to the local repo without updating your local branch. To update your local branch either by executing merge or pull requests to your local repo to be up to date with its remote.

3) Pull: Get updates from your remote branch into your local branch. basically keeps your branch up to date with its remote one. Pull does a fetch and then a merge into your local branch.
So just use Pull to get your local branch updates from its remote one.

3) Pull vs Fetch: git pull does a git fetch. so if you used git pull this means that your have executed git fetch.  you can execute fetch if you want to get the updates but do not want to merge them into yor local branch yet.

5) Push: sends committed changes to remote branch so it is shared with others.


Basic rules to work with git in Visual Studio that everyone should be aware of before start coding:
This section i cover all needed actions to work with using git in Visual Studio Team Explorer window.




1) You need to click on Sync in team explorer to refresh the current branch from the remote branch. followed by pull to get those changes merged into the current local branch. sync just show status but to actually merge those changes you need to click on pull link.

2)  You need to click on Changes in team explorer every time you want to check in or get latest updates of the current branch.

3) You need to click on Branches in team explorer every time you want to manage branches in Visual Studio.

4) You need to click on Pull Requests in team explorer every time you want to manage pull requests in Visual Studio.


A) Setup a project for your team using Git in VSTS:

1) Visit http://visualstudio.com.
2) Login to your account.
3) Click on New button to create a new git project.



4) Once you hit create project button, the project will be created in few seconds and then we will use Visual Studio to do some necessary steps.

5) To start using Visual Studio with the created project, Click on Code tab for the newly created project "MicrosoftRocks".

6) Click on Clone in Visual Studio button.
7) This will open up VS and then open up Team Explorer window.
8) You need to click on "Clone this repository" this will allow you to create a local repo of the remote repo we have just created in VSTS.



9) Select a local repo folder and click on Clone.



10) Now, VS shows a message that we can create a new project or solution.


11) You can go ahead and create any project in VS, the only thing to notice to uncheck create a new Git repository checkbox when creating any new project since we have created already our local repo.




12) First things first, you need to exclude bin and debug folders from getting checked in Git. So, click on Settings in Team explorer -- > Click on Repository Settings link under Git --> Click on Add link to add .gitignore file.



13) To edit .gitignore file, click on edit link. Then, add the following at the bottom of the file:

# exclude bin and debug folders
bin
debug


14) Build the project and then we will do our first check in to the master branch.

15) Click on Home icon in team explorer to go back to the home page to manage source control options.

16)  Click on Settings, Type a check in message and then click on Commit Staged.



17) Commit staged action has check in all our changes to our local repo, these changes have not been share to the remote, so we need to click on sync to share it with others.
You will notice, that VS shows you a sync link afterwards so you can sync changes immediately or your can click on Sync from team explorer and then click on Push.



18) Now, the project is ready in the master branch for everyone with git ignore file before everyone will create his own branch and start developing.


B) Create your own branch in Visual Studio:

1) Every developer in a team, should create his own branch and get the latest from master to start developing in our project.

2) From Visual Studio, Click on master branch from the bottom bar and click on new branch.



3) Enter your branch name "dev1" and from which branch your want to create yours "master" and then click on Create Branch button. This step will create your own branch and get latest from master and switch to your branch to start coding in it.

4) You will notice, the name of the current branch has changed from master to dev1 in Visual Studio. now you can start working in your branch.

5) Once you are done coding a feature or at a good point to check in some code, Follow these steps to check in your changes:
  • Click on Changes in team explorer, write a message and then click on Commit All button.
  • You can also click on sync to push these changes to the remote branch in VSTS online.
  • Remember, these changes are still in your branch no one else has seen it until you submit it to the master branch.

6) Publish your branch: It is important to publish your branch to VSTS, Follow these steps:
  • From team explorer, click on branches.
  • Right click on your branch.
  • Click on Publish Branch.




C) How to submit your code to the master branch:

1) First, you need to make sure that your local master branch is up to date. to do that, switch to master branch and click on sync and then click on pull in Team explorer window.

2) Second, Switch back to your branch "dev1" and then click on branches in team explorer.

3) Click on Merge link.

4) Select to merge from "master" into "dev1" and then click on Merge. This step will merge all master changes into your branch so your branch will get other people work and fix any conflict (if any) before submitting all changes to master using Pull Request (PR) action.



5) Now, we need to submit all these changes after making sure there are no conflicts to the master branch. Click on Pull Requests in Team explorer.

6) Click on New Pull Request link.



7) This will open Visual Studio online webpage to submit new pull request.
8) Click on New Pull Request button.

9) Submitted Pull Requests (PRs) will be either approved or rejected by the repository admins. unless you are an admin, you will be able to approve/reject and complete submitted PRs in any project and therefore these changes are committed/merged to the master branch.


10) Click on Complete button to complete the pull request. Visual Studio will prompt a popup window if you want to add any notes and then click on Complete merge button. This is the last step to merge your changes into master after your PR has been approved.



11) Repeat the same steps every time you want to merge your changes into master using PRs.



Hope this article has shown in detailed walk-though how to work in a team using Git in Visual Studio Team Services and manage your code checkins/checkouts/merge/branching and PRs in Git.

Enjoy!

-- ME








Monday, August 17, 2015

mysql is not recognized as an internal or external command

Hi,

I am using Visual Studio 2015 for developing cordova apps. I have installed MySql tools yesterday and since then eveytime i build or deploy my app, i get this error:

mysql is not recognized as an internal or external command


Even though i don't use MySQL in my cordova app but still i am not able to build or deploy any cordova app in Visual Studio 2015.

The meaning of this error message is: The system couldn't locate the mysql.exe in your system.

I am running Windows 10, here is the steps to fix that:

1) From the Cortana search, open up the control panel.
2) Navigate to System & Security, and then System.
3) Click on Advanced System Settings from the left pane.
4) Click on Environment variables.
5) Try to find Path system variable and click on Edit.

Copy the variable value in any editor and do the following:

a) Enclose any mySQL component path between double quotation "".
b) Add the mySQL.exe path at the end of the variable. You need to look for the installation path for MySQL installation and grab the installation folder which contains MySQL.exe and add it to the Path system variable.
In My Case the path for MySQL.exe is:
C:\Program Files\MySQL\MySQL Server 5.6\bin


Below is the Path system variable after the update: [[ notice the highlighted yellow section is what i have updated ]].

C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common Files\Microsoft Shared\Microsoft Online Services;C:\Program Files (x86)\Common Files\Microsoft Shared\Microsoft Online Services;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;%USERPROFILE%\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\nodejs\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;"C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5\";"C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5\Doctrine extensions for PHP\";"C:\Program Files\MySQL\MySQL Server 5.6\bin"


6) Click on Ok to save your changes.
7) Close and re-open VS 2015 (THIS IS A MUST)
8) Try to build or deploy your cordova app! it starts working again...

Enjoy.


Friday, April 25, 2014

Unable to retrieve metadata for unrecognized element 'providers' when adding a controller in VS 2013

Hi,

I was trying to add a new controller in my project using Visual Studio 2013. I was using Code First Entity Framework for my data access. I tried to build and clean the project few times before adding the new controller; but still was getting this error message when  adding a new controller to my web api project.

Here is the error message:


The solution is the following:
1) Open the web.config file in your project.
2) Scroll down until you see entity framework section.
3) This is how it will be looking:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

4) Remove the providers section.
5) Save and you will be able to add new controllers!

Hope this helps!


Thursday, April 17, 2014

Error when running web applications that reference SharePoint dlls in IIS Express

Hi All,

I was developing a web application that reference SharePoint 2013 dlls, and since SharePoint server dlls in general runs on a 64 bit environment, i want to use IIS express in Visual Studio 2013 without the need to use full local IIS that runs on 64 bit.

I was getting this error message when i am running my web application:

Could not load file or assembly or one of its dependencies. 

and i was seeing in the yellow error page that the VS 2013 is using IIS express under c:\ program files (86)\ IIS Express folder which is the 32 bit.


I want to switch IIS express to 64 bit so i will be able to run my web application that references 64 bit SharePoint dlls. here is the solution for this:

From Visual Studio 2013 IDE:

Click on :  Tools --> Options --> Projects and Solutions --> Web Projects  --> Use the 64 bit version of IIS Express --> check this checkbox and save.


Once you save, make sure you exit any instance of the IIS express and try to re-run your project! It will run with no issues!

Enjoy!


Friday, November 02, 2012

Getting Started Windows 8 Store Apps Resources

Hi Folks,

I'm writing this post to share the resources that every software engineer or developer needs to get started with Windows 8 Store App development.

First, Before heading out and install Development resources (SDK) to start playing and exploring with windows 8 store app tools looks like. here is some sites you need to read to have a basic understanding about windows 8 store apps principles, design and concepts:

1) Windows Store Apps development center:
This site is the main site that contains all materials you want to get or read about Windows Store Apps design and development.
http://msdn.microsoft.com/en-us/windows/apps

2) First document i suggest to read, Windows 8 Product Guide for Developers, find it here:
http://msdn.microsoft.com/en-US/windows/apps/hh852650

3) Spend some time understanding the API reference for Win Store apps using JavaScript, C#,C++ or VB.NET:
This source shows how to use,understand & explore Windows 8 API using different programming languages. Using C# or JavaScript to build HTML Store Apps is different than using Traditional JavaScript in some manner.
http://msdn.microsoft.com/library/windows/apps/br211369

4) Get some basic understanding of Metro Style Store apps guidelines and principles:
Even if you are not a designer, it is crucial to have basic understanding of designing Views and pages.
http://msdn.microsoft.com/library/windows/apps/hh779072

After the previous four steps, you should be able to build your development box with Windows 8,VS 2012 Express, Blend and SQL 2012 Express, so you proceed to the following resources.
Downloads link:
http://msdn.microsoft.com/en-US/windows/apps/br229516

5) Getting started with development tutorials:
Get some samples, tutorials to get dirty hands working with VS 2012, Blend and All windows Store necessary tools to get up to speed in development.
http://msdn.microsoft.com/library/windows/apps/br211386

Since I'm a C# guy, here is the Get Started Development resources for C# Developers:
http://msdn.microsoft.com/en-us/library/windows/apps/hh974581.aspx

Once you reach this step, you should be able to build your first windows store app. now the time for deployment/licensing and selling your application.

6) Selling you application:
Get to know the available markets, languages and how to get paid.
http://msdn.microsoft.com/library/windows/apps/hh694064

I will keep updating this post as i find good resources to read  for early adopters!

Hope this helps,

Regards,
Mostafa E.

Friday, July 13, 2012

What's New in VS 2012 & .NET Framework 4.5 RC

Hi Folks,

This post is my first blog post after i got back from my vacation in Egypt and getting married! I had a wonderful summer time with my family and here we go back to .NET life style!

After i installed VS 2012 RC on my Development VM and then started to play around with the new IDE. Here are what is called fascinating in the new VS 2012 RC & the framework 4.5.

1) Portable Class Libraries: Now you can develop portable class libraries that can be used to target different framework ranging from .NET framework, Silverlight and Windows Phone 7 or even XBOX 360!!.



Even this is a great option in VS 2012 but please note that also you don't have an option to add references that are not compatible with targeted frameworks.

For example, if you tired to add a .NET framework assembly in portable class library you will find very few assemblies are available, check out below screen shot.


Note: If you tried to add any references that is not compatible with your targeted platforms then VS 2012 will warn you with incompatibility warning!

Read more about Portable Class Library:
http://msdn.microsoft.com/en-us/library/gg597391(v=vs.110)


2) Asynchronous File I/O
Now you can develop code for intensive I/O operations without blocking the main thread!. with that being said, new keywords in C# and VB.NET have been added and supported by the compiler through using async and await keywords which are available in C# and VB.NET.


public async Task CopyFilesAsync(StreamReader Source, StreamWriter Destination)
{
    char[] buffer = new char[0x1000];
    int numRead;
    while ((numRead = await Source.ReadAsync(buffer, 0, buffer.Length)) != 0)
    {
        await Destination.WriteAsync(buffer, 0, numRead);
    }
}


Read more about Async File I/O in .NET 4.5:
http://msdn.microsoft.com/en-us/library/kztecsys(v=vs.110)

3) Web: Supports for HTML5,Async http request and response, WebSockets & support for CDN in Script Manager fallback.

4) Enhancements in WCF including: easier asp.net compatibility mode, HTTPs endpoints with IIS, Generate WSDL by appending ?singleWSDL, Simplification for generating configuration files and more.

5) Enhancements in Windows Workflow Foundation (WF).

6) Enhancements in Windows Presentation Foundation (WPF): A new Ribbon control, New INotifyDataError Interface and more.

Read more about what's new for WPF in .NET 4.5:
http://msdn.microsoft.com/en-us/library/bb613588(v=vs.110)

7) Metro Style Applications
You can now build Metro Style application using VS 2012, A subset of .NET 4.5 is available when building Metro Style Applications and its called .NET APIs.

To get an overview about Metro Style applications:
http://msdn.microsoft.com/en-us/library/windows/apps/br230302.aspx


- Reference:
What's new in .NET Framework 4.5:
http://msdn.microsoft.com/en-us/library/1d971dd7-10fc-4692-8dac-30ca308fc0fa(v=vs.110)


Have Fun with VS 2012 RC and hope this helps!

Have a wonderful weekend everyone.

Regards,
Mostafa Elzoghbi