Freigeben über


Mobile Services .NET support + Source Control

Yesterday we launched preview support for a .NET based Mobile Services backend (for more information see here). For this release we’ve focused on the standard right click -> publish workflow in Visual Studio to publish your backend logic to the cloud, but if you’re a git fan fear not! Publishing your .NET based backend with git is actually really easy:

  1. Follow our existing tutorial for getting started, but stop when you get to the section on publishing your mobile service.

  2. Initialize a git repository in the same directory as your solution:
    > git init

  3. Add an appropriate .gitignore file to avoid committing binaries to your repository. You can download one from https://www.gitignore.io/api/visualstudio, but be aware you’ll need to make one tweak: find the line with #packages/* and remove the # at the front. Save the .gitignore file in the root of your repository.

  4. Add and commit your files to the repository
    > git add .
    > git commit –m "initial commit"

  5. Add your mobile service as a remote (replace <servicename> below with the name of your mobile service):
    > git remote add origin https://<servicename>.scm.azure-mobile.net/<servicename>.git

  6. Push to your mobile service:
    > git push origin master

  7. When prompted for credentials, you have a few options (we'll be making this easier in the future):

    1. If you have setup source control for a node.js based mobile service on the same subscription, the same credentials you use for that will work here
    2. You can take the publish settings file that you would download when following the normal publishing flow, and open it in a text editor and find the username and password as:
      userName="<username>" userPWD="<password>"
       
  8. After providing the credentials, your code will be pushed to your mobile service and a deployment script will use NuGet Package Restore to download all the necessary binaries. You should see some output that looks like this:

    remote: KuduSync.NET from: 'C:\DWASFiles\Sites\dotnet\Temp\2295442c-37d2-4d6b-8365-3b047109b840' to: 'D:\home\site\wwwroot'
    remote: Copying file: 'Web.config'
    remote: Copying file: 'bin\dotnetService.dll'
    remote: Finished successfully.
    remote: Deployment successful.
    To https://dotnet.scm.azure-mobile.net/dotnet.git
    + 3fff290...bfc6c99 master -> master

  9. That’s it! Hit your mobile service and you should see your changes have taken effect.

Of course you can follow similar steps to above using the built in git tooling in Visual Studio 2013, and in future releases you can expect the process of setting up git to become even easier and we'll have support for integration with hosted repositories such as GitHub and Codeplex. Happy hacking!