Thoughts, Tips and Tricks on what I'm currently do for a living. Currently most of my spare time is spent on contributing to Akka.NET.

Friday, January 10, 2014

Kafka 0.8.0 on Windows

Getting Kafka 0.8.0 running on Windows isn’t straight forward if you follow the instructions. They are somewhat misleading, and the bat files are old. But with correct instructions and updated bat files it’s easy and can be done under 10 minutes. Some say you need Cygwin in order to run Kafka. This is not true. Only Server JRE is required.

Step 0. Prerequisite – Java SE Server JRE

You need Java SE Server JRE in order to run Kafka. If you have JDK installed, you already have Server JRE installed.

  1. Download Java SE Server JRE
    http://www.oracle.com/technetwork/java/javase/downloads/index.html
    For me Chrome changed the extension. If that happens change it back to .tar.gz in order to unpack it.
  2. Unpack it to a folder, for example c:\JreServer
    Update the system environment variable PATH to include C:\JreServer\jre\bin (Control Panel and search for environment variable).

Step 1. Download Kafka

  1. Download the binaries for Kafka from http://kafka.apache.org/downloads.html
  2. Unzip to a folder, for example c:\kafka
Update the bat files

Unfortunately the bat files for Kafka 0.8.0 are full of errors, so in order to start Zookeeper and Kafka they must be replaced.

  1. Download updated windows bat files from https://github.com/HCanber/kafka/releases
  2. Unzip and copy them into c:\kafka\bin\windows (overwrite the files already there)
Update Config

The config files need to be updated.

  1. Open config\server.properties and locate log.dirs=/tmp/kafka-logs. If you keep the default it will result in an error later on. Set it to a full path without . or .. in it and with forward slashes. Example:
    log.dirs=c:/kafka/kafka-logs
  2. This step is optional but you might want to set the data directory for Zookeeper as well. Open config\zookeeper.properties and locate dataDir=/tmp/zookeeper. Example:
    dataDir=c:/kafka/zookeeper-data

Step 2. Start the server

Note! Before executing the commands below you need to change directory to the folder where you unzipped Kafka:

cd c:\kafka
  1. Start Zookeeper in a Command Prompt or PowerShell Console.
    .\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
  2. Start Kafka in another Command Prompt or PowerShell Console.
    .\bin\windows\kafka-server-start.bat .\config\server.properties

Step 3. Create a topic

  1. Create a topic.
    .\bin\windows\kafka-create-topic.bat --zookeeper localhost:2181 --replica 1 --partition 1 --topic test
  2. List topics.
    .\bin\windows\kafka-list-topic.bat --zookeeper localhost:2181

Step 4. Send some messages

  1. Start Console Producer
    .\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test
  2. Write some messages
    This is a message 
    This is another message

Step 5. Start a consumer

  1. Start Console Consumer
    .\bin\windows\kafka-console-consumer.bat --zookeeper localhost:2181 --topic test --from-beginning

 

Building from sources

See Building Kafka 0.8.0 from sources on Windows

Wednesday, January 30, 2013

Nancy and Owin

This is a short post on how to run NancyFX in an Owin pipeline on a HttpListener Host.

Update

David Fowler (@davidfowl), and an anonymous commenter, pointed out there was a better way to set up Owin hosting. The code has been updated.

Note, before we start. Since HttpListener might require permissions, the easiest way round this is running as an administrator, or starting VS2012 as administrator. You shouldn’t be doing this in production. Configuring HTTP and HTTPS on MSDN.

Create a Console App

Create a Console App and install the following packages in the Package Manager Console. Note that prerelease nuget packages are used.

Install-Package Microsoft.Owin.Host.HttpListener -Pre
Install-Package Microsoft.Owin.Hosting -pre
Install-Package Nancy.Hosting.Owin

These packages will also be installed when the packages above are installed:

Owin, Nancy

The Code

First we need a Nancy Module:

public class SampleModule : NancyModule
{
  public SampleModule()
  {
    Get["/"] = _ => "Hello World!";
  }
}

Then we need to configure the Owin application to run Nancy.

public class Startup
{
  public void Configuration(IAppBuilder app)
  { //Uses an extension method that adds Nancy at the end of an Owin pipeline
    app.RunNancy();  
  }
}

The extension method used to configure the app:

public static class NancyOwinAppBuilderExtensions
{
  public static IAppBuilder RunNancy(this IAppBuilder builder)
  {
    return RunNancy(builder, new DefaultNancyBootstrapper());
  }

  public static IAppBuilder RunNancy(this IAppBuilder builder, INancyBootstrapper bootstrapper)
  {
    var nancyOwinHost = new NancyOwinHost(bootstrapper);
    return RunNancy(builder, nancyOwinHost);
  }

  public static IAppBuilder RunNancy(this IAppBuilder builder, NancyOwinHost host)
  {
    return RunApp(builder, host.ProcessRequest);
  }

  private static IAppBuilder RunApp(IAppBuilder builder, Func<IDictionary<string, object>, Task> app)
  {
    return UseFunc(builder, next => app);
  }

  private static IAppBuilder UseFunc(IAppBuilder builder, Func<Func<IDictionary<string, object>, Task>, Func<IDictionary<string, object>, Task>> middleware)
  {
    return builder.Use((object)middleware, new object[0]);
  }
}

Lastly we put everything together and starts the Owin Server:

class Program
{
  static void Main(string[] args)
  {
    var url = "http://+:8080";

    using (WebApplication.Start<Startup>(url))
    {
      Console.WriteLine("Running on http://localhost:8080", url);
      Console.WriteLine("Press enter to exit");
      Console.ReadLine();
    }
  }
}

That’s it. Hit F5 to run it. Visit http://localhost:8080/ in a browser.

Package versions

The following packages were used in the code.

Microsoft.Owin.Host.HttpListener version=0.18.0-alpha
Microsoft.Owin.Hosting version=0.18.0-alpha

Nancy version=0.15.3
Nancy.Hosting.Owin version=0.15.3
Owin version=1.0

Download code

https://gist.github.com/4676779

Friday, September 23, 2011

Using the Topshelf Shelving Bootstrapper in a Console App

Note! This was written for Topshelf 2.2.2.0 and things might have changed in newer versions.

Topshelf

Topshelf (http://topshelf-project.com) is a framework for building Windows services. The service can either be standalone or one that is hosted by Topshelf. The latter style is called shelving (and the service you write is called a shelf) and it enables xcopy deploy of your service, instead of stop service, uninstall, copy, install, start.

Debugging a shelf

The problem with using the shelving style for your service is debugging. The documentation explains how to do it (http://topshelf-project.com/debugging-a-topshelf-shelf/), but it’s not that neat as it involves modifying where your build outputs the dlls.

An easier way, at least for me, would be to debug the shelf service by starting it from a console app, i.e. as a standalone service, without any need to modify where the output from the build goes. Ideally the console app would be as simple as possible, just reusing the code from the shelf.

A shelf service is initiated and configured by a bootstrapper (a class that inherits the interface Bootstrapper<T>) but unfortunately, if you compare the configuration for a standalone service with the shelf bootstrapper, they are not configured the same way, so reusing the configuration from the shelf bootstrapper in a standalone service seems not possible, but it’s actually quite easy.

Reuse the bootstrapper

Instead of implementing Bootstrapper<T> derive from this class instead:

public abstract class BootstrapperBase<T> : Bootstrapper<T> where T : class
{
  void Bootstrapper<T>.InitializeHostedService(IServiceConfigurator<T> cfg)
  {
    InitializeHostedService(cfg);
  }

  public abstract void InitializeHostedService(ServiceConfigurator<T> cfg);
}

Instead of implementing
void InitializeHostedService(IServiceConfigurator<T> cfg)
you implement
void InitializeHostedService(ServiceConfigurator<T> cfg)

The bootstrapper in the example at http://topshelf-project.com/documentation/shelving/ becomes (changes are highlighted)

public class AShelvedClockBootstrapper :
      BootstrapperBase<TheClock>
{
  public override void InitializeHostedService(ServiceConfigurator<TheClock> cfg)
  {
    cfg.ConstructUsing(n => new TheClock());
    cfg.WhenStarted(s =>
    {
      XmlConfigurator.Configure(new FileInfo(Path.Combine(
                      AppDomain.CurrentDomain.BaseDirectory,
                      "clock.log4net.config")));
      s.Start();
    });
    cfg.WhenStopped(s => s.Stop());
  }
}

In the console app you start the service like this:

static void Main(string[] args)
{
  XmlConfigurator.ConfigureAndWatch(new FileInfo(".\\log4net.config"));
 
  HostFactory.Run(x =>
  {
    x.Service<TheClock>(
        s => new AShelvedClockBootstrapper().InitializeHostedService(s)); x.RunAsLocalSystem();   x.SetServiceName("TheClock"); }); }

Wednesday, August 31, 2011

“Hello World” with OWIN (on Kayak)

A link to all code can be found at the end of this post.

When I started implementing an OWIN compatible web framework I couldn’t find any examples on how to get started with OWIN. Jef Claes has an example but this seems to be for an older draft of OWIN. So this post is about how to create a really simple OWIN web application in C#. It’s inspired by Jef Claes code and uses code from Benjamin van der Veen´s example.

Please Note! This post was written when OWIN was Draft 1.0, using Kayak 0.7.2 and Gate 0.1.4. Things might have changed since this post.

Set up the project

Start by creating a C# Console App.

Install the NuGet package Gate.Kayak. This will install the these packages too: Gate & Kayak.

Kayak is is an asynchronous HTTP server written in C#. Gate.Kayak brings OWIN support to Kayak. If you want to host your OWIN app in another environment use another gate like Gate.AspNet or Gate.Wcf.

Create the Kayak Web Server

In order to set up a Kayak web server, we need to tell Kayak three things: What endpoint to listen to; how to handle exceptions and shut downs; and how to handle the incoming requests.

Main() – Configuring and Starting the Server

In this example the Main method of the Console App configures the Kayak server and starts it.

static void Main(string[] args)
{
   //Create the endpoint for incoming requests to Kayak    
   var kayakEndPoint = new IPEndPoint(IPAddress.Any, 5500);
   Console.WriteLine("Listening on " + kayakEndPoint);

   //Start Kayak and call the method Startup.Configuration when starting
    //Let SchedulerDelegate handle exceptions and shut downs
   KayakGate.Start(new SchedulerDelegate(), kayakEndPoint, Startup.Configuration);
}

An endpoint on port 5500 is created. When Kayak is starting it will configure itself by calling the Startup.Configuration method (more on this below), and when stopped, or when an exception is thrown, SchedulerDelegate handles this.

SchedulerDelegate

The methods in SchedulerDelegate class is called when exceptions during Kayak´s event loop occurs and when Kayak is being stopped. We’ll just write messages to the Console.

public class SchedulerDelegate : ISchedulerDelegate
{
   public void OnException(IScheduler scheduler, Exception e)
   {
       // called whenever an exception occurs on Kayak's event loop.
       // this is good place for logging. here's a start:
       Console.WriteLine("Exception on scheduler");
       Console.Out.WriteStackTrace(e);
   }

   public void OnStop(IScheduler scheduler)
   {
       // called when Kayak's run loop is about to exit.
       // this is a good place for doing clean-up or other chores.
       Console.WriteLine("Scheduler is stopping.");
   }
}

Startup.Configuration

Next we need to tell Kayak what to do with incoming requests. The method Startup.Configuration is responsible for that and it will be called when Kayak is starting. In this example, we specified it explicitly in the Main method, but if you were to host the OWIN application on Asp.Net using Gate.AspNet this method will automatically be found and invoked (it’s a convention in Kayak). So creating class with the name Startup with a static method Configuration makes your application more easily portable to other Gate hosts.

public class Startup
{
   // called automatically when Kayak starts up.
   public static void Configuration(IAppBuilder builder)
   {
       // we'll create a very simple pipeline:
       var app = new HelloWorldOwinApp();
       builder.Run(Delegates.ToDelegate(app.ProcessRequest));
   }
}

First our OWIN application is instantiated and then Kayak is told to to let the app´s ProcessRequest method handle all incoming requests.

HelloWorldOwinApp

The primary interface in OWIN is the application delegate. An application delegate takes three parameters: an environment dictionary, a response callback, and an error callback. The HelloWorldOwinApp class exposes the method ProcessRequest that has the same signature as the application delegate specified in OWIN Draft 1.0 and this is where all the fun happens.

If the requested resource, i.e. the path, is the root, “/”, we return a Hello World html page. Otherwise a 404 page is returned.

public class HelloWorldOwinApp
{
   public void ProcessRequest(
        IDictionary<string, object> environment,
       Action<string, IDictionary<string, string>,
               Func<Func<ArraySegment<byte>, Action, bool>,
               Action<Exception>, Action, Action>> responseCallBack,
       Action<Exception> errorCallback)
   {
       var path = environment["owin.RequestPath"] as string;
       var responseHeaders = new Dictionary<string, string>();
       ArraySegment<byte> responseBody;
       string responseStatus;
       if (path == "/")
       {
           responseStatus = "200 OK";
           responseHeaders.Add("Content-Type", "text/html");
           responseBody = new ArraySegment<byte>(Encoding.UTF8.GetBytes((
                   "<!doctype html><html><head><meta charset=\"utf-8\">" +
                       "<title>Hello World</title></head>" +
                   "<body><strong>Hello world</strong></body>" +
                   "</html>")));
       }
       else
       {
           responseStatus = "404 Not Found";
           responseHeaders.Add("Content-Type", "text/html");
           responseBody = new ArraySegment<byte>(Encoding.UTF8.GetBytes((
                   "<!doctype html><html><head><meta charset=\"utf-8\">" +
                       "<title>404 Not Found</title></head>" +
                   "<body>The resource cannot be found.</body>" +
                   "</html>")));
       }
       responseCallBack(
           responseStatus,
           responseHeaders,
           (next, error, complete) =>   // This is the Body Delegate
           {
               next(responseBody, null);
               complete();
               return () => { };
           });
   }
}

The signature is hideous. The people behind OWIN are well aware of this, and considered interfaces in an assembly that all had to implement, but, thankfully, decided to go with using Funcs and Actions instead. This means that there is no OWIN.dll you have to reference, and therefor no versioning conflicts can occur.

Except from the signature, this method is pretty straightforward. We get the relative path from the environment dictionary. If it’s “/” we return a Hello World html page. Otherwise a 404 page is returned.

Returning the resource is a bit special. Instead of just returning some kind of object with headers, status and body content the responseCallBack is invoked. This is necessary for everything to be asynchronous. The callback has as three arguments: the response status; response headers; and a delegate (the next-error-complete-delegate) for retrieving the body content.

The delegate is called the Body Delegate and it is invoked by the host whenever it is ready to receive the body content. The signature of the delegate makes it possible to return chunks of the body. But to keep it simple we will return everything in one chunk, and that is what the next(responseBody, null) call does. responseBody is an ArraySegment (basically a byte array with information about which part of the array the consumer should use).

For simple applications, like this, you don’t have to understand how the Body delegate is intended to be used. Just copy-paste this example, and add the content to responseBody.

Say Hello!

Start the console app. In a browser navigate to http://localhost:5500. You should see a page with “Hello World” in bold. Now go to http://localhost:5500/NotThere and you’ll get a 404 page.

That’s it. Now you have everything you need to create a OWIN web application.

Code

The code can be found on github gist. Show all code.

Wednesday, March 9, 2011

An extension method for creating a strict mock in FakeItEasy

The FakeItEasy framework prefers that you don’t create strict mocks, but whenever you need one this extension method might come in handy.

/// <summary>Creates a strict mock of type <typeparamref name="T"/>.</summary>
/// <typeparam name="T">The type of the object to fake.</typeparam>
/// <returns>A FakeItEasy fake configured to behave as a strict mock.</returns>
public static T Mock<T>()
{
  var fake = A.Fake<T>();
  Any.CallTo(fake).Throws(new Exception(string.Format("An unexpected method was called on the fake object {0}.", typeof(T))));
  return fake;
}

To create a strict mock:

var foo = AStrict.Mock<IFoo>();

After you have configured your mock in this fashion you can configure any "allowed" calls as usual, for example:

A.CallTo(() => foo.Bar()).Returns("bar");

 

Example and code based on: http://code.google.com/p/fakeiteasy/wiki/StrictMocks

Sunday, February 13, 2011

Set Custom Tool in the Item Template file

Documentation for setting the Custom Tool property for a project item created from an item template is not exactly easily found.

There are two things you need in the .vstemplate-file (I’ll assume you know how to create item templates). First you need to include a WizardExtension-node and next you need to specify a CustomTool attribute on the ProjectItem. Both are marked in yellow below.

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <TemplateData>
    <DefaultName>MyFile.txt</DefaultName>
    <Name>My File</Name>
    <Description>My File</Description>
    <ProjectType>CSharp</ProjectType>
    <SortOrder>1</SortOrder>
    <Icon>__TemplateIcon.ico</Icon>
  </TemplateData>
<WizardExtension> <Assembly>Microsoft.VSDesigner, Version=10.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> <FullClassName>Microsoft.VSDesigner.ProjectWizard.ItemPropertyWizard</FullClassName> </WizardExtension>
<TemplateContent> <References /> <ProjectItem SubType="Code" TargetFileName="$fileinputname$.txt" ReplaceParameters="false" CustomTool="MyCustomTool">MyFile.txt</ProjectItem> </TemplateContent> </VSTemplate>

Thursday, December 30, 2010

How to register for a WP7Dev account

Technorati Tags: ,,,

Want to create applications for the Windows Phone 7 (WP7)? You need to register in order to be able to do that, even if you you only want to deploy the application to your own phone and not to the AppHub. Since I haven’t seen any description of the process I wrote down what I had to to. Note that I live in Sweden and the process might vary by countries, but most likely this is what you have to go thru as an individual non-US developer.

1. Register and pay

Register at http://windowsphone.create.msdn.com/AppSubmission

Make sure:

Beware that the fee is said to be $99 USD but in reality this might differ, especially if you´re outside US. In Sweden it will cost you €99. Also beware that the amount you’re accepting, which for me was 919 SEK (€99) is not the amount you’ll be charged. To that a tax of 15% is added, so I was charged 1057 SEK ($150). I’m not sure if it’s legal to ask for acceptance of one amount and then charge another. But, according to Shaun Taulbee, Microsoft:

“Price adjustments are coming, and I'm told refunds will be automatically applied for those who registered since October”
http://forums.create.msdn.com/forums/p/67701/423198.aspx#423198

2. Email: Confirm the email address! /Microsoft

After registering and paying an email will be sent to the email you provided during registration (which might differ from the Live account) in order to confirm the email address. It contains a link that needs to be opened.

3. Email: Approve request! /GeoTrust

Now you should receive an email form GeoTrust. If you haven’t received it within 24 hrs (remember to check your Spam/Junk email folder first) you should contact GeoTrust directly, according to the FAQ: http://create.msdn.com/en-US/home/faq/windows_phone_7#wp7faq10
For me the email came instantly.

Open the link to GeoTrust that was sent to you in the email an approve the order.
”Your order has been successfully approved and your authenticated identity validation status will be reflected on the Windows Phone 7 AppHub within two business days.”

4. Email: Send identification confirmation! /GeoTrust

You just have to wait for the next email from GeoTrust:

“In order for GeoTrust to confirm your information in terms of Microsoft's requirements, GeoTrust must receive a copy of your valid government issued photo identification (for example: a passport or driver's license), attached to the Identification Confirmation Letter below.”

You can fax them the information or send it by email, which is what I did: Print out a copy of the letter. Fill the fields at the bottom (all the info is on your passport). Sign it. Scan the letter with your passport at the designated position. Email GeoTrust with the scanned letter as an attachment.

5. Email: Your email was received. /GeoTrust

After a while you’ll receive an email acknowledging the receipt of your Identification Confirmation email.

“The verification process will be completed within 1-2 business days. If you have any questions, please contact us.”

6. “Welcome to the Windows Phone Marketplace developer program”

The next email should be from Microsoft welcoming you to the program. For me, it took 6 hours to receive this email.

You’re done…. Sort of…. In order to receive payment for your apps you’ll need to do more, but I’ll stop here.

Shortcutting the process

“Wow, that’s many steps and a whole lot of waiting”, you may think. Yeah, it is. But there is a way to speed up the process which worked for me and a friend of mine. Step 1-3 runs smoothly (no human interaction I would guess), but instead of waiting up to 2 days for step 4 and 5 you can contact GeoTrust via their chat: https://www.geotrust.com/support/chat/order-processing.html

Instead of waiting for step 4, ask them for status of your order.
After sending the email in step 4, ask them to check they have received the email, and that it contains the correct information.

For me the steps 1-6 took 2.5 days.

Register the phone

Connect the phone to your computer. Make sure Zune starts. Start the “Windows Phone Developer Registration” program (from the start menu) and enter your Live ID and Password and click Register. Make sure the phone is not locked. For me it took some attempts. I had to restart the phone and then clicking retry a few times.

Thursday, September 2, 2010

How to get the Single File Generator sample running

I’ve started developing a CustomTool for Visual Studio 2010. Microsoft has released a sample with documentation on how to implement a Custom Tool. The code can be found here:
http://code.msdn.microsoft.com/SingleFileGenerator

Visual Studio 2010 SDK must be installed.

The documentation states “Rebuild the class library and start running it”. Didn’t work. Got the error message saying a class library cannot be started. To be able to debug this is what I did:

  1. In Solution Explorer, right click on Generator Sample and select the menu item Properties.
  2. On the Debug tab, click the Start external program radio button.
  3. Browse or enter the path to VS 2010, typically:
    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
  4. As Command line arguments, enter
    /ranu /rootsuffix Exp
  5. As Working directory, specify the folder for VS2010:
    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
  6. Set a break point in the XmlClassGenerator.GenerateCode method.
  7. Press F5 to start debugging.
  8. A new Visual Studio is started.
  9. Follow the instructions in the documentation (create a new class library, create an xml file, fill with content, set CustomTool for file) and the break point will be hit.

Thursday, December 3, 2009

How to remotely connect to ASP.Net Development Server

The ASP.Net Development Server (webdev.webserver.exe), which is included with Visual Studio, is used when testing web applications locally when IIS isn’t installed. The ASP.Net Development Server will only serve pages to browser requests on the local computer, so a colleague of yours cannot have a look at what you’re doing, since ASP.Net Development Server will not serve pages to another computer.

image

In order to remotely connect to the ASP.Net Development Server a proxy must be used that accepts remote connections and proxies traffic to and from the ASP.Net Development Server.

I searched the internet for a suitable proxy but I couldn’t find one that is small and easy to use (ok, I admit, I didn’t search that long :-) so I wrote one based on proxy code from http://www.mentalis.org/soft/projects/proxy/.  It’s probable not the most elegant piece of code ever written but it will have to do.

To start the proxy just pass the port number to it:

Proxy.exe 62200

Incoming traffic to port 80 (standard http port) is proxied to 62200, so if your computer’s name is YourComputer, your colleague can connect on the url: http://YourComputer/

To listen to another port than 80, specify it as the second argument:

Proxy.exe 62200 15555

Incoming traffic to port 15555  is proxied to 62200, so the url will be: http://YourComputer:15555/

Download

Download executable and source here:
http://cid-1591ce8777facfb4.skydrive.live.com/browse.aspx/Public/Code/Proxy

Thursday, December 18, 2008

How to deploy a VS Database Project GDR using vsdbcmd

With the release of Visual Studio Team System 2008 Database Edition GDR we now have the possibility to use a standalone command for deploying a database project. Unfortunately the documentation for the new vsdbcmd is so full of errors that you cannot use it, see for example “Command-line Reference for VSDBCMD (Deployment and Schema Import)” and “How to: Prepare a Database for Deployment From a Command Prompt by Using VSDBCMD ”. Seems to be written for a previous version.

Properties

The documentation states that you should specify properties using this syntax:

/p:PropertyName:PropertyValue    INCORRECT!

The correct syntax is:

/p:PropertyName=PropertyValue 

Verbose and quiet

It also states that there exists a /verbose or /v option. This option do not exist. It has been removed. It’s verbose by default and you can use the undocumented /quiet or /q to turn of verbosity [source].

Invalid property names

The common deployment properties list isn’t right either. For example the TargetDatabaseName is in fact called TargetDatabase. Have a look in the .sqldeployment and .deploymanifest files for proper naming. These files exists in the directory created when building the project, for example MyDbProject/sql/debug/.

Deploy-example

Below is an example of how to deploy a database project that has been built by Visual Studio or Team Server Foundation (TFS).

Start a command prompt and change directory to the directory that was created when the project was built (for example MyDbProject/sql/debug/) and execute the command below (on a single line).

"%ProgramFiles%\Microsoft Visual Studio 9.0\VSTSDB\deploy\vsdbcmd"
/a:Deploy
/ConnectionString:"Data Source=MyServer;Integrated Security=True;"
/dsp:SQL
/manifest:MyDbProject.deploymanifest
/p:TargetDatabase=MyDb
/dd

This will create a .sql file and deploy it, i.e. execute it on the server. If you remove the /dd option the .sql will be created but not deployed.