<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Visual Studio &#8211; Cognim &#8211; Internet development</title>
	<atom:link href="https://www.cognim.co.uk/category/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.cognim.co.uk</link>
	<description>Enterprise system implementation. Making the complex simple</description>
	<lastBuildDate>Tue, 10 Nov 2015 10:10:24 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">91553907</site>	<item>
		<title>Gulp and Visual Studio: Code quality</title>
		<link>https://www.cognim.co.uk/gulp-and-visual-studio-code-quality/</link>
					<comments>https://www.cognim.co.uk/gulp-and-visual-studio-code-quality/#respond</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Tue, 10 Nov 2015 09:58:30 +0000</pubDate>
				<category><![CDATA[Gulp]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://www.cognim.co.uk/?p=5258</guid>

					<description><![CDATA[This is Part 4 is my series on using Gulp with Visual Studio. So far we&#8217;ve covered setting up Visual Studio for use with Gulp, processing SASS, and getting the files ready for deployment. Part 1: Setting up Gulp with Visual Studio Part 2: Getting SASSy Part 3: Deployment: minification and concatenation Part 4: Code [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This is Part 4 is my series on using Gulp with Visual Studio. So far we&#8217;ve covered setting up Visual Studio for use with Gulp, processing SASS, and getting the files ready for deployment.</p>
<ul>
<li><a href="https://www.cognim.co.uk/getting-started-with-gulp-and-vs/" target="_blank">Part 1: Setting up Gulp with Visual Studio</a></li>
<li><a href="https://www.cognim.co.uk/gulp-and-visual-studio-sass/">Part 2: Getting SASSy</a></li>
<li><a href="https://www.cognim.co.uk/gulp-vs-minification/">Part 3: Deployment: minification and concatenation</a></li>
<li>Part 4: Code quality: tests and linting</li>
<li>Part 5: Thoughts on Gulp</li>
</ul>
<p>In this post I want to talk about JavaScript code quality.</p>
<h3>Code quality: tests and linting</h3>
<p>JavaScript is a notoriously quirky language &#8211;  the tricky &#8220;this&#8221; operator, lack of block level scoping, the ability to use variables before declaring them, &#8220;==&#8221; vs &#8220;===&#8221;, etc etc.</p>
<p>We can do a number of things to tighten up our code quality. We can run tests to ensure our code works as expected, and we can run a linting program to catch any syntatic mistakes before running our code. Combining this with Gulp gives a nice workflow for development.</p>
<h4>Linting with JSHint</h4>
<p><a href="http://stackoverflow.com/questions/8503559/what-is-linting" target="_blank">Linting</a> is a process of running a program to analyse code for potential problems, catching bugs before the program gets executed. Douglas Crockford created <a href="http://www.jslint.com/" target="_blank">JSLint</a> in 2011, and of course there is a <a href="https://www.npmjs.com/package/gulp-jslint" target="_blank">gulp plugin</a> for it. However, I prefer to use <a href="http://jshint.com/" target="_blank">JSHint</a> &#8211; a community offshoot of JSLint that allows for more customisation and is slightly more relaxed in its defaults. You can find a good comparison of the two <a href="http://stackoverflow.com/a/10763615" target="_blank">here</a>.</p>
<p>First, I would seperate out any third-party libraries or frameworks you have into their own folder(s). In my opinion this is good practice anyway, but especially if we are running linting &#8211; we don&#8217;t want failures on code we haven&#8217;t written! Next, we want to add the <a href="https://www.npmjs.com/package/gulp-jshint" target="_blank">plugin</a> to our package.json:</p>
<pre class="lang:js decode:true ">{
  "scripts": { "install": "echo Done" },
    
  "devDependencies": {
    "gulp": "~3.9.0",
    "gulp-load-plugins": "~0.10.0",
    "gulp-jshint": "~1.11.2",
    // other plugins here
  } 
}</pre>
<p>Then, add the Gulp task to our gulpfile:</p>
<pre class="lang:c# decode:true" title="gulpfile.js">var sources = ['./Scripts/*.js', '!./Scripts/libs/*.js'];

gulp.task('watch-lint', function () {
    gulp.watch(sources, ['lint']);
});

gulp.task('lint', function () {
    return gulp.src(sources)
        .pipe(plugins.jshint({
            strict: true,
            predef: [""]
        }))
        .pipe(plugins.jshint.reporter('default'))
        .pipe(plugins.jshint.reporter('fail'))
    ;
});</pre>
<p>Here&#8217;s a line by line breakdown of the important stuff:</p>
<ul>
<li>Line 1: Define the JavaScript files we want linting, excluding any third party libraries and frameworks</li>
<li>Line 3-5: Set up a watch to run the linting task whenever we make a change to our JavaScript</li>
<li>Line 7: Set up our linting task</li>
<li>Line 8-12: Send our files to JSHint. JSHint has a number of options you can set to define how lenient or strict you want it to be. You can look at the <a href="http://jshint.com/docs/" target="_blank">docs</a> to get an idea of what you can set. Here I&#8217;m only using the strict option (<a href="http://www.nczonline.net/blog/2012/03/13/its-time-to-start-using-javascript-strict-mode/" target="_blank">here</a> is a good blog explaining strict mode). There is also a section to define any global variables you&#8217;re using that should be ignored &#8211; for example if you&#8217;re using Angular you&#8217;ll want to add &#8220;angular&#8221; here</li>
<li>Line 13-14: Send the output of the linting to some inbuilt reporters &#8211; one to output the results to console and one to raise an error for any failures</li>
</ul>
<p>Now we can add the watch task to our default task, and we&#8217;ll have linting every time we change our code.</p>
<h4>Tests with Karma</h4>
<p>One of the great things about Gulp is that you can get a Gulp task to run other Node based packages directly. For example, you can run <a href="http://karma-runner.github.io" target="_blank">Karma</a> within a task, without having to use a plugin. Combined with <a href="http://phantomjs.org/" target="_blank">PhantomJS</a>, a headless browser, you get a great unit testing framework for your JavaScript. First, add the packages:</p>
<pre class="lang:c# decode:true " title="package.json">{
  "scripts": { "install": "echo Done" },
    
  "devDependencies": {
    "gulp": "~3.9.0",
    "karma-jasmine": "~0.3.6",
    "karma": "~0.13.9",
    "karma-phantomjs-launcher": "~0.2.1"
    // other plugins here
  } 
}</pre>
<p>Then, we&#8217;ll need to add our karma config file (karma.conf.js) at the root of the project :</p>
<pre class="lang:js decode:true" title="karma.conf.js">module.exports = function (config) {
    config.set({
        files: ['./Scripts/*.js',
                './Scripts/Specs/**/*.js',
        ],

        exclude: ['./Scripts/libs/*.js'],

        frameworks: ['jasmine'],

        autoWatchBatchDelay: 1000,

        reporters: ['progress'],

        browsers: ['PhantomJS']
    });
};</pre>
<p>One thing I&#8217;ve found using Karma in Visual Studio: often Karma can crash in Visual Studio with an &#8220;EBUSY&#8221; error. I haven&#8217;t found an adequate explanation for this yet &#8211; I think it&#8217;s because when you modify and save a file Visual Studio writes a temporary file to replace the file you are saving, which doesn&#8217;t sit well with Node. This can be mitigated by setting the &#8220;autoWatchBatchDelay&#8221; to 1000, which waits 1 second after any change before running tests.</p>
<p>Finally, our gulp task:</p>
<pre class="lang:js decode:true">var Server = require('karma').Server;

gulp.task('runTests', function () {
    new Server({
        configFile: __dirname + '/karma.conf.js',
        singleRun: false
    }).start();
});</pre>
<p>Here, we are simply firing up Karma from within a Gulp task and passing in our karma config file. We are also telling Karma to watch our files for any changes and re-run our tests if they change. If you are going to run this task on a build server (and you should), you&#8217;ll need to configure the singleRun variable here. This can be done by using <a href="https://www.npmjs.com/package/yargs" target="_blank">yargs</a> to pass in a variable to switch this behaviour.</p>
<p>There we are! There is a commit of all the changes <a href="https://github.com/edwardridge/Gulp-and-Visual-Studio/commit/92ba6c092e262261171c642aa765129238e00283">here</a>, which includes a sample test. I highly recommend using both linting and unit tests when writing JavaScript code, and Gulp is great at running these tasks for us.</p>
<p>Next, in the last past I want to share my thoughts on Gulp, specifically within the .NET ecosystem.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/gulp-and-visual-studio-code-quality/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5258</post-id>	</item>
		<item>
		<title>Gulp and Visual Studio: concatenation and minification</title>
		<link>https://www.cognim.co.uk/gulp-vs-minification/</link>
					<comments>https://www.cognim.co.uk/gulp-vs-minification/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Thu, 24 Sep 2015 15:04:44 +0000</pubDate>
				<category><![CDATA[Gulp]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://www.cognim.co.uk/?p=5268</guid>

					<description><![CDATA[In my previous blog I wrote about how we can use Gulp to compile SASS. This time it&#8217;s all about how we can use Gulp in Visual Studio to prepare files for a release by minifying and concatenating them. I&#8217;ve put up a project using the standard MVC 5 template for this series of posts [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In my previous blog I wrote about how we can use Gulp to compile SASS. This time it&#8217;s all about how we can use Gulp in Visual Studio to prepare files for a release by minifying and concatenating them. I&#8217;ve put up a project using the standard MVC 5 template for this series of posts <a href="https://github.com/edwardridge/Gulp-and-Visual-Studio" target="_blank">here</a></p>
<ul>
<li><a href="https://www.cognim.co.uk/getting-started-with-gulp-and-vs/" target="_blank">Part 1: Setting up Gulp with Visual Studio</a></li>
<li><span style="color: #000000;"><a href="https://www.cognim.co.uk/gulp-and-visual-studio-sass/" target="_blank">Part 2: Getting SASSy</a></span></li>
<li><span style="color: #999999;"><a href="https://www.cognim.co.uk/gulp-vs-minification">Part 3: Deployment: minification and concatenation</a></span></li>
<li><span style="color: #999999;">Part 4: Code quality: tests and linting</span></li>
<li><span style="color: #999999;">Part 5: Thoughts on Gulp</span></li>
</ul>
<h3>Small is beautiful</h3>
<p>To increase the speed of a site, and to save bandwidth, we want to:</p>
<ul>
<li>Have as few requests for the smallest files possible</li>
<li>Cache these files for as long as possible</li>
</ul>
<p>We can achieve this by concatenating and minifying the files, then adding a hash of the files contents to the filename so they can be cached indefinitely.</p>
<p>There are a number of different ways of approaching minification and concatenation with Gulp, and a lot of different plugins and plugin combinations. The following is a style that has worked for me, you may need to adjust it to suit your own workflow.</p>
<h3>Plugins</h3>
<p>There are a number of plugins we will need:</p>
<ul>
<li><a href="https://www.npmjs.com/package/gulp-useref">gulp-useref</a> for concatenation</li>
<li><a href="https://www.npmjs.com/package/gulp-uglify">gulp-uglify</a> and <a href="https://www.npmjs.com/package/gulp-minify-css">gulp-minify-css</a> for minifcation of JavaScript and CSS respectively</li>
<li><a href="https://github.com/sindresorhus/gulp-rev">gulp-rev</a> and <a href="https://github.com/jamesknelson/gulp-rev-replace">gulp-rev-replace</a> for revisioning</li>
<li><a href="https://www.npmjs.com/package/gulp-filter">gulp-filter</a> for filtering files to process them independently</li>
</ul>
<p>Lets add these to the package.json:</p>
<pre class="lang:js decode:true">{
  "scripts": { "install": "echo Done" },
    
  "devDependencies": {
    "gulp": "~3.9.0",
    "gulp-load-plugins": "~0.10.0",
    "gulp-useref": "~1.3.0",
    "gulp-uglify": "~1.2.0",
    "gulp-minify-css": "~1.2.1",
    "gulp-rev": "~5.1.0",
    "gulp-rev-replace": "~0.4.2",
    "gulp-filter": "~3.0.0"
  } 
}
</pre>
<h3>Referencing scripts and CSS</h3>
<p>Now we&#8217;ll want to add our CSS and JavaScript files to our pages. These are put in commented <strong>build blocks</strong> that let gulp-useref know where a section it should concatenate is. So, at the top of the page (here it&#8217;s the _Layout.cshtml page) we reference the CSS:</p>
<pre class="lang:xhtml decode:true">&lt;!-- build:css /dist/site.css --&gt;
    &lt;link href="/Content/bootstrap.css" rel="stylesheet" /&gt;
    &lt;link href="/Content/Site.css" rel="stylesheet" /&gt;
&lt;!-- endbuild --&gt;    
<!-- endbuild --></pre>
<p>In the first comment, we define two things:</p>
<ul>
<li>The first part, &#8220;build:css&#8221; tells useref that this be a CSS block</li>
<li>The second is the location of the concatenated file that will eventually be referenced (more on this later)</li>
</ul>
<p>We do the same at the bottom with the JavaScript:</p>
<pre class="lang:xhtml decode:true">&lt;!-- build:js /dist/libs.js --&gt;
    &lt;script src="/Scripts/Libraries/jquery.js"&gt;&lt;/script&gt;
    &lt;script src="/Scripts/Libraries/bootstrap.js"&gt;&lt;/script&gt;
    &lt;script src="/Scripts/Libraries/respond.js"&gt;&lt;/script&gt;
&lt;!-- endbuild --&gt;<script src="/Scripts/Libraries/respond.js"></script><!-- endbuild --></pre>
<p>We can have multiple build blocks of the same type (e.g. multiple JavaScript blocks) so we can have one for libraries (Angular, jQuery etc) which will change less frequently than the code we write.</p>
<h3>The Gulp task</h3>
<p>Now for the biggie &#8211; the actual task itself. I&#8217;ll put it here and go through it in more detail below:</p>
<pre class="nums:true lang:js decode:true">gulp.task('minifyFilesForRelease', function () {

    var cssFilter = plugins.filter('**/*.css', { restore: true });
    var jsFilter = plugins.filter('**/*.js', { restore: true });

    var assets = plugins.useref.assets();
    gulp.src('./**/*.cshtml')
        .pipe(assets)

        //Process JavaScript
        .pipe(jsFilter)
        .pipe(plugins.uglify())
        .pipe(plugins.rev())
        .pipe(assets.restore())
        .pipe(jsFilter.restore)
        
        //Process CSS
        .pipe(cssFilter)
        .pipe(plugins.minifyCss({
            keepSpecialComments: 0
        }))
        .pipe(plugins.rev())
        .pipe(assets.restore())
        .pipe(cssFilter.restore)

        .pipe(plugins.useref())
        .pipe(plugins.revReplace({
            replaceInExtensions: ['.js', '.css', '.html', '.cshtml']
        }))
        .pipe(gulp.dest(function (data) {
            return data.base;
        }
        ));
});</pre>
<p>Here&#8217;s a line by line breakdown of what&#8217;s happening:</p>
<ul>
<li>Line 1: Define the task</li>
<li>Line 3-4: Setup some filters we will use later to separate out the CSS and JavaScript for individual processing</li>
<li>Line 6: Reference the assets object of useref which will return the build blocks we setup earlier</li>
<li>Line 7: Get all our cshtml files</li>
<li>Line 8: Get all our build blocks in these files</li>
<li>Line 11: Filter our build blocks to just the JavaScript</li>
<li>Line 12: Minify the JavaScript</li>
<li>Line 13: Revision the JavaScript</li>
<li>Line 14-15: Remove the filters, so we have access to all our build blocks again</li>
<li>Line 18: Filter our build blocks to just the CSS</li>
<li>Line 19-21: Minify the CSS removing any and all comments</li>
<li>Line 22: Revision CSS</li>
<li>Line 23-24: Remove the filters again</li>
<li>Line 26: Replace the commented, unprocessed build block in our cshtml files with the processed ones</li>
<li>Line 27-29: Add the revision number to the processed files (note we need to include cshtml files here)</li>
<li>Line 30-32: Replace the original cshtml files. We need to specify a destination here, and as we have views in multiple  folders we can use <a href="http://stackoverflow.com/a/29437418">this technique by </a><a href="http://stackoverflow.com/users/1212682/yiling">Yiling</a> to overwrite a file regardless of its location</li>
</ul>
<p>Phew, there&#8217;s a lot there! If you run this task each build block in our cshtml files will be replaced with a single, minified, revisioned file.</p>
<p>Before:</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-1.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-large wp-image-5287" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-1.png?resize=1024%2C574&#038;ssl=1" alt="gulp-concat-1" width="1024" height="574" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-1.png?resize=1024%2C574&amp;ssl=1 1024w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-1.png?resize=300%2C168&amp;ssl=1 300w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-1.png?w=1197&amp;ssl=1 1197w" sizes="auto, (max-width: 1000px) 100vw, 1000px" /></a></p>
<p>After:</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-2.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-large wp-image-5286" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-2.png?resize=1024%2C575&#038;ssl=1" alt="gulp-concat-2" width="1024" height="575" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-2.png?resize=1024%2C575&amp;ssl=1 1024w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-2.png?resize=300%2C169&amp;ssl=1 300w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-2.png?w=1200&amp;ssl=1 1200w" sizes="auto, (max-width: 1000px) 100vw, 1000px" /></a></p>
<h3>Running in Release mode</h3>
<p>We only want to run this task when we&#8217;re putting together a release, whether that&#8217;s manual or (much better!) <a href="https://www.cognim.co.uk/know-exactly-what-youve-released-with-git-teamcity-and-octopus/">automated</a>. To do this, add a PreBuildEvent that runs the Gulp task before a release build. Go to the project properties, then Build Events and add the following to &#8220;Pre-build event command line&#8221;:</p>
<pre class="lang:default decode:true ">if $(ConfigurationName) == Release (
   cd $(ProjectDir)
   npm install
   gulp minifyFilesForRelease
)</pre>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-4.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="size-large wp-image-5284 aligncenter" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-4.png?resize=1024%2C571&#038;ssl=1" alt="gulp-concat-4" width="1024" height="571" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-4.png?resize=1024%2C571&amp;ssl=1 1024w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-4.png?resize=300%2C167&amp;ssl=1 300w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-4.png?w=1136&amp;ssl=1 1136w" sizes="auto, (max-width: 1000px) 100vw, 1000px" /></a></p>
<p>This will then run our minifying task only on a Release build.</p>
<p>Lastly, as we are adding the minified files to a &#8220;dist&#8221; folder that doesn&#8217;t exist during development, we&#8217;ll need to add this folder after each build. Open up the csproj for the web project, and at the very end add the following:</p>
<pre class="lang:c# decode:true">&lt;Target Name="AfterBuild"&gt;
    &lt;ItemGroup&gt;
      &lt;Content Include="dist\*.*" /&gt;
    &lt;/ItemGroup&gt;
 &lt;/Target&gt;</pre>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-3.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="size-large wp-image-5285 aligncenter" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-3.png?resize=1024%2C564&#038;ssl=1" alt="gulp-concat-3" width="1024" height="564" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-3.png?resize=1024%2C564&amp;ssl=1 1024w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-3.png?resize=300%2C165&amp;ssl=1 300w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/09/gulp-concat-3.png?w=1136&amp;ssl=1 1136w" sizes="auto, (max-width: 1000px) 100vw, 1000px" /></a></p>
<p>This will include the contents of our dist folder after each build.</p>
<h3>Wrapping up</h3>
<p>We now have an automated process for minifying and concenating files that doesn&#8217;t intefere with the development process. The commit for everything is <a href="https://github.com/edwardridge/Gulp-and-Visual-Studio/commit/a2a5eb8b4df4457db3c1025d2fb7162d39f0c1af" target="_blank">here</a>.</p>
<p>Happy Gulping!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/gulp-vs-minification/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5268</post-id>	</item>
		<item>
		<title>Gulp and Visual Studio: Getting SASSy</title>
		<link>https://www.cognim.co.uk/gulp-and-visual-studio-sass/</link>
					<comments>https://www.cognim.co.uk/gulp-and-visual-studio-sass/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Fri, 04 Sep 2015 08:41:10 +0000</pubDate>
				<category><![CDATA[Gulp]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://www.cognim.co.uk/?p=5230</guid>

					<description><![CDATA[Getting SASSy with Gulp in Visual Studio In my previous blog I showed you how to set up Visual Studio for use with Gulp. Now I want to show you how you can use it in everyday development, including processing SASS, running tests, linting your code and getting ready for deployment. In this series of [&#8230;]]]></description>
										<content:encoded><![CDATA[<h3>Getting SASSy with Gulp in Visual Studio</h3>
<p>In my <a href="https://www.cognim.co.uk/getting-started-with-gulp-and-vs/" target="_blank">previous blog</a> I showed you how to set up Visual Studio for use with Gulp. Now I want to show you how you can use it in everyday development, including processing SASS, running tests, linting your code and getting ready for deployment.</p>
<p>In this series of posts I&#8217;ll talk about how you can use Gulp with Visual Studio to run your common front end tasks:</p>
<ul>
<li><a href="https://www.cognim.co.uk/getting-started-with-gulp-and-vs/" target="_blank">Part 1: Setting up Gulp with Visual Studio</a></li>
<li><span style="color: #000000;"><a href="https://www.cognim.co.uk/gulp-and-visual-studio-sass/" target="_blank">Part 2: Getting SASSy</a></span></li>
<li><span style="color: #999999;">Part 3: Deployment: minification and concatenation</span></li>
<li><span style="color: #999999;">Part 4: Code quality: tests and linting</span></li>
<li><span style="color: #999999;">Part 5: Thoughts on Gulp</span></li>
</ul>
<p>The code I&#8217;ll be showing is based off a standard MVC 5 project. If you want the code I&#8217;ve created a GitHub project for it <a href="https://github.com/edwardridge/Gulp-and-Visual-Studio/">here.</a></p>
<h3>Basic Gulpfile + package.json</h3>
<p>Throughout these examples I&#8217;ll be using <a href="https://www.npmjs.com/package/gulp-load-plugins" target="_blank">gulp-load-plugins</a> &#8211; an awesome meta-plugin that takes all your Gulp plugins from your package.json and attaches them to an object. At the start, the package.json file looks like this:</p>
<pre class="lang:js decode:true" title="package.json">{
  "scripts": {"install": "echo Done"},
    
  "devDependencies": {
    "gulp": "~3.9.0",
    "gulp-load-plugins": "~0.10.0"
  } 
}
</pre>
<p>N.B. I like outputting something to the console after installing packages as the default is to not output anything, which can be a little confusing!</p>
<p>The basic gulpfile looks like this:</p>
<pre class="lang:js decode:true">var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();

gulp.task('default', ['']);</pre>
<p>Now, any plugins we add to our package.json will immediately be available on the plugins object.</p>
<h3>Processing SASS</h3>
<p>I&#8217;m a big fan of <a href="http://sass-lang.com/" target="_blank">SASS</a> for developing CSS as it helps keep my CSS clean and <a href="https://en.wikipedia.org/wiki/Don't_repeat_yourself" target="_blank">DRY</a>. SASS files need processing, and Gulp can do this for you. As a bonus, we can add <a href="http://code.tutsplus.com/tutorials/source-maps-101--net-29173" target="_blank">sourcemaps</a> so that when we inspect the page in Firefox, Chrome or IE 11 we refer back to the original SASS rather than the processed CSS. As a double bonus, we can use <a href="http://livereload.com/" target="_blank">LiveReload</a> to reload the page and automatically see our changes whenever we make a change to the SASS (note with LiveReload on Windows you&#8217;ll need the <a href="https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en" target="_blank">Chrome extension</a> for the best experience).</p>
<p>First off, we add the SASS file. For this demo project, based on MVC 5, this is simple &#8211; rename the Site.css file to Site.scss. As SASS is a superset of CSS, all valid CSS is valid SASS.</p>
<p>Next, we add the plugins we&#8217;ll need to the package.json:</p>
<pre class="lang:js decode:true">{
  "scripts": { "install": "echo Done" },
    
  "devDependencies": {
    "gulp": "~3.9.0",
    "gulp-load-plugins": "~0.10.0",
    "gulp-sass": "~2.0.4",
    "gulp-sourcemaps": "~1.5.2",
    "gulp-autoprefixer": "~2.3.1",
    "gulp-livereload": "~3.8.0"
  } 
}</pre>
<p>Next, add the gulp tasks &#8211; one to process the SASS into CSS, and another to watch the SASS files and recompile whenever we make a change:</p>
<pre class="nums:true lang:js decode:true" title="gulpfile.js">var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();

gulp.task('sass', function () {
    gulp.src('./Content/*.scss')
        .pipe(plugins.sourcemaps.init())
        .pipe(plugins.sass())
        .pipe(plugins.autoprefixer())
        .pipe(plugins.sourcemaps.write())
        .pipe(gulp.dest('./Content'))
        .pipe(plugins.livereload())
    ;
});

gulp.task('watch-sass', function () {
    plugins.livereload.listen();
    gulp.watch('./Content/*.scss', ['sass']);
});

gulp.task('default', ['watch-sass']);</pre>
<p>Here&#8217;s a line by line breakdown of what is happening within our &#8216;sass&#8217; task:</p>
<ul>
<li>Line 5: Grab all our SASS files from the Content folder. At the moment this is just the Site.scss file, but as we build this up we&#8217;ll want to add different SASS files for different parts of the project</li>
<li>Line 6: Initialise the sourcemaps. Note that <strong>this must be done before they get processed</strong></li>
<li>Line 7: Process the SASS to generate the CSS</li>
<li>Line 8: Use <a href="https://github.com/postcss/autoprefixer" target="_blank">autoprefixer</a> to add any vendor-specific prefixes to the CSS. The defaults for the <a href="https://www.npmjs.com/package/gulp-autoprefixer" target="_blank">plugin</a> target any browser with &gt;1% share, which is eminently sensible</li>
<li>Line 9: Insert the sourcemaps into the generated CSS</li>
<li>Line 10: Write the generated CSS back to the Content directory</li>
<li>Line 11: Notify LiveReload that we&#8217;ve made changes</li>
</ul>
<p>The &#8216;watch-sass&#8217; task simply tells LiveReload to start listening, watches our SASS files for any changes, and when they are changed runs our &#8216;sass&#8217; task. This watch has also been added to the default task, so will run automatically. Now, when we make a change to the Site.scss file the css will automatically get generated, and we get all the other goodness from our other plugins too.</p>
<h4>Sourcemaps</h4>
<p>Below I&#8217;ve changed the Site.scss file so that the text in the Jumbtron is blue, and have inspected it in Chrome. You&#8217;ll notice the red box in the inspector refers to the Site.scss file (not the generated Site.css file) , thanks to sourcemaps.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-process-files-1.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-large wp-image-5242" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-process-files-1.png?resize=910%2C1024&#038;ssl=1" alt="gulp-process-files-1" width="910" height="1024" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-process-files-1.png?resize=910%2C1024&amp;ssl=1 910w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-process-files-1.png?resize=267%2C300&amp;ssl=1 267w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-process-files-1.png?w=960&amp;ssl=1 960w" sizes="auto, (max-width: 910px) 100vw, 910px" /></a></p>
<h4>LiveReload</h4>
<p>If you open the site in Chrome and start the LiveReload extension, any time a change is made to the SASS the web page will automatically reload with the changes. Here the color of the jumbotron text is switching between red and blue, and automatically updating:</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-live-reload.gif?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-full wp-image-5241" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-live-reload.gif?resize=800%2C378&#038;ssl=1" alt="gulp-live-reload" width="800" height="378" /></a></p>
<h3>Wrapping up</h3>
<p>So there we are! Automatic processing of SASS with Gulp, along with a few other goodies. The commit for eveything I&#8217;ve shown is <a href="https://github.com/edwardridge/Gulp-and-Visual-Studio/commit/8d00491f141298732887df2b87c36a569bc165de" target="_blank">here. </a></p>
<p>One thing to note is that in this task we didn&#8217;t do anything minification to the CSS &#8211; I&#8217;ll come on to that in my next post.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/gulp-and-visual-studio-sass/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5230</post-id>	</item>
		<item>
		<title>Getting started with Gulp in Visual Studio 2013 and 2015</title>
		<link>https://www.cognim.co.uk/getting-started-with-gulp-and-vs/</link>
					<comments>https://www.cognim.co.uk/getting-started-with-gulp-and-vs/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Fri, 07 Aug 2015 09:56:50 +0000</pubDate>
				<category><![CDATA[Gulp]]></category>
		<category><![CDATA[Node]]></category>
		<category><![CDATA[NodeJs]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://www.cognim.co.uk/?p=5148</guid>

					<description><![CDATA[In the last few years a rich set of front end development tools has emerged for building complex web applications. Gulp in particular has taken off in a huge way. However, .NET development is lagging when it comes to adoption of these tools. This is all set to change, especially with the release of ASP.NET 5 where Gulp will become [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In the last few years a rich set of front end development tools has emerged for building complex web applications. Gulp in particular has taken off in a huge way. However, .NET development is lagging when it comes to adoption of these tools. This is all set to change, especially with the release of ASP.NET 5 where Gulp will become part of the standard project setup. But, what is Gulp, and how do you use it in Visual Studio?</p>
<h2>What is Gulp?</h2>
<p><a href="http://gulpjs.com/">Gulp</a> is a build process for front end development. Gulp automates all of the repetitive tasks you have to do to prepare your front end files (such as JavaScript and CSS) for development and deployment. Gulp uses small, simple, composable plugins to that let you define exactly what happens to the files in your build.</p>
<h4>Common tasks you can get Gulp to automate</h4>
<ul>
<li>Minifying JavaScript/CSS/images</li>
<li>Concatenating JavaScipt/CSS files</li>
<li>Running JavaScript lint tooling</li>
<li>Compiling your SASS/LESS</li>
<li>Compiling TypeScript/CoffeeScript</li>
<li>Running JavaScript tests (eg Karma, Jasmine, Mocha)</li>
<li>Transpiling ES6 into ES5</li>
<li>Minifying Angular without breaking Dependency Injection</li>
<li>&#8230;and many more</li>
</ul>
<p>To install and use Gulp, you&#8217;ll need npm. Which begs the question&#8230;</p>
<h4>What is npm?</h4>
<p>npm is the package manager for <span class="tooltips " style="" title="Node is a runtime environment built in JavaScript. It is somewhat equivalent to the .NET CLR - and for getting set up it is not necessary to know much more than that"><span style="text-decoration: underline;">Node</span></span>. It&#8217;s a front-end equivalent to NuGet &#8211; you can use it to install and update packages and their dependencies. We&#8217;ll be using it to install Gulp and all its plugins.</p>
<h2>How to set up Gulp in Visual Studio</h2>
<p>Currently you can set up Gulp in Visual Studio 2013 and 2015. If you have 2015, skip the first 3 points as they come with Visual Studio 2015. Note that the screenshots are taken using Visual Studio 2013 with a standard MVC 5 project template.</p>
<ol>
<li>
<h4>Install Node/npm.</h4>
<p>You can install Node <a href="https://nodejs.org/" target="_blank">from here</a>. What we&#8217;re really after here isn&#8217;t Node, it&#8217;s npm (which comes installed with Node).</li>
<li>
<h4>Install Gulp.</h4>
<p>After installing npm, open up a Console window, and enter:</p>
<blockquote><p>npm install gulp -g</p></blockquote>
<p>This will install Gulp. The &#8220;-g&#8221; option installs it globally, so you can run Gulp commands anywhere.</li>
<li>
<h4>Install the Grunt Launcher Visual Studio Extension.</h4>
<span class="tooltips " style="" title="Grunt is another build process for front end development. Grunt favours configuration, while Gulp favours code. I am not going to get into the merits of each here!"><a href="https://visualstudiogallery.msdn.microsoft.com/dcbc5325-79ef-4b72-960e-0a51ee33a0ff" target="_blank">Grunt Launcher</a></span> provides menu options to install npm packages and run Gulp tasks from within Visual Studio.</li>
<li>
<h4>Add Gulp to your project</h4>
<p>At the root of your web project, add a new JSON file called package.json with the following contents:</p>
<pre class="lang:js decode:true">{
    "devDependencies": {
        "gulp":  "3.9.0"
    }   
}
</pre>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-1.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="  wp-image-5173 aligncenter" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-1.png?resize=889%2C420&#038;ssl=1" alt="gulp-blog-1" width="889" height="420" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-1.png?resize=1024%2C484&amp;ssl=1 1024w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-1.png?resize=300%2C142&amp;ssl=1 300w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-1.png?w=1379&amp;ssl=1 1379w" sizes="auto, (max-width: 889px) 100vw, 889px" /></a> The <span class="tooltips " style="" title="Note a standard package.json will contain other information such as a description, author and a repository for the code"><span style="text-decoration: underline;">package.json</span></span> is a npm file we use to define metadata about our project. Here we are listing the (front end) dependencies for developing our project &#8211; this will include plugins for running Gulp tasks. For now, we just want to add Gulp to our project.</p>
<p>Now, right-click on the package.json file and click &#8220;NPM install packages&#8221; (if you&#8217;ve installed Grunt Launcher) to add it to our project.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/NPM-install-vid.gif?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class=" size-full wp-image-5171 aligncenter" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/NPM-install-vid.gif?resize=784%2C600&#038;ssl=1" alt="NPM install vid" width="784" height="600" /></a></p>
<p>You can ignore those warnings for now &#8211; you can add the metadata it is complaining about later.</p>
<p>This will add a node_modules folder in your project folder, where all our npm packages will be kept. Within that will be Gulp.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-3.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-full wp-image-5179" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-3.png?resize=334%2C423&#038;ssl=1" alt="gulp-blog-3" width="334" height="423" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-3.png?w=334&amp;ssl=1 334w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-3.png?resize=237%2C300&amp;ssl=1 237w" sizes="auto, (max-width: 334px) 100vw, 334px" /></a></li>
<li>
<h4>Add a Gulpfile</h4>
<p>Next we want to add a Gulpfile, where we will define the steps for our build process. Add a JavaScript file called gulpfile.js to the root of the project, and add the following code:</p>
<pre class="striped:true lang:js decode:true">var gulp = require('gulp');

gulp.task('default', function () {
    console.log('Hello world!');
});
</pre>
<p>&nbsp;</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-2.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone  wp-image-5174" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-2.png?resize=884%2C418&#038;ssl=1" alt="gulp-blog-2" width="884" height="418" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-2.png?resize=1024%2C484&amp;ssl=1 1024w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-2.png?resize=300%2C142&amp;ssl=1 300w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/gulp-blog-2.png?w=1379&amp;ssl=1 1379w" sizes="auto, (max-width: 884px) 100vw, 884px" /></a><br />
In line 1 we load Gulp. On line 3 we define a new Gulp task. A task is a step, or a set of steps, that Gulp will execute. A task takes a function that it will run &#8211; in this case we simply log to the console. A task also has a name &#8211; here it&#8217;s called &#8220;default&#8221; and as you might guess it runs automatically when we run Gulp.</p>
<p>We can now run this task by right-clicking on the gulpfile.js and clicking the &#8220;Gulp&#8221; menu item added by the Grunt Launcher extension.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Run-Gulpfile-Vid.gif?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-full wp-image-5172" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Run-Gulpfile-Vid.gif?resize=764%2C600&#038;ssl=1" alt="Run Gulpfile Vid" width="764" height="600" /></a></p>
<p>&nbsp;</p>
<p>Now Visual Studio is running our task, and outputting &#8220;Hello world!&#8221; to the output window. We&#8217;re done! Well, not quite&#8230;</li>
</ol>
<h2>Doing something actually useful</h2>
<p>Hello World is all well and good, but what about automating something useful? One common task is minifying CSS files, and that&#8217;s what we&#8217;ll do here.</p>
<ol>
<li>
<h4>Add the plugins</h4>
<p>Change your package.json file to the following:</p>
<pre class="striped:true lang:js decode:true">{
    "devDependencies": {
        "gulp": "3.9.0",
        "gulp-uglifycss": "1.0.4",
        "gulp-rename": "1.2.2"
    }
}
</pre>
<p>Here we&#8217;ve added two new packages, gulp-uglifycss (which minifies css) and gulp-rename (which renames files passed into it). We can now use these in our task.</li>
<li>
<h4>Modify the task</h4>
<p>Change the gulpfile.js to the following:</p>
<pre class="striped:true nums:true nums-toggle:true lang:js decode:true">var gulp = require('gulp'),
    uglifycss = require('gulp-uglifycss'),
    rename = require('gulp-rename');

gulp.task('default', function () {
    return 
         gulp.src(['./Content/*.css', '!./Content/*.min.css'])
        .pipe(uglifycss())
        .pipe(rename({
            suffix: ".min",
            extname: ".css"
        }))
        .pipe(gulp.dest('./Content'));
});
</pre>
<p>Here&#8217;s a line by line breakdown of what the task is doing:<br />
Line 1-3: Add references to the plugins we just added in our package.json<br />
Line 7: Get the CSS files from our Content directory (excluding any .min files)<br />
Line 8: Pipe (i.e. pass) the files to gulp-uglifycss, which minifies them<br />
Line 9-12:  Rename the minified files to include a .min suffix<br />
Line 13: Save the minified files back to our Content folder</p>
<p>Now, we can run this task to automatically minify all our CSS files.</p>
<p>And there we are! We now have a process that will save us from a repetitive boring task, and we can build on this to automate lots of other tasks.</li>
</ol>
<h2>Next steps</h2>
<p>Note that for brevity I have excluded everything that isn&#8217;t necessary for getting Gulp set up in Visual Studio. There are a few things you will want to do next to get fully set up:</p>
<ol>
<li>
<h4>Install the Task Runner Explorer extension</h4>
<p>You can install the <a href="https://visualstudiogallery.msdn.microsoft.com/8e1b4368-4afb-467a-bc13-9650572db708" target="_blank">Task Runner Explorer</a> Visual Studio extension to run tasks automatically on each build or every time the project opens.</li>
<li>
<h4>Install NPM Package Intellisense</h4>
<p><a href="https://visualstudiogallery.msdn.microsoft.com/65748cdb-4087-497e-a394-2e3449c8e61e" target="_blank">NPM Package Intellisense</a> gives you package intellisense when installing packages and plugins.</li>
<li>
<h4>Add more plugins</h4>
<p>Nearly any task you want to automate will <a href="http://gulpjs.com/plugins" target="_blank">have a plugin here</a> &#8211; there are over 1500 at time of writing.</li>
</ol>
<p>Happy Gulping!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/getting-started-with-gulp-and-vs/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5148</post-id>	</item>
		<item>
		<title>5 Lesser Known Reasons To Upgrade To Visual Studio 2015</title>
		<link>https://www.cognim.co.uk/5-lesser-known-reasons-to-upgrade-to-visual-studio-2015/</link>
					<comments>https://www.cognim.co.uk/5-lesser-known-reasons-to-upgrade-to-visual-studio-2015/#respond</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Sat, 01 Aug 2015 14:00:10 +0000</pubDate>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2015]]></category>
		<guid isPermaLink="false">http://www.cognim.co.uk/?p=5086</guid>

					<description><![CDATA[Searching the web there are plenty of articles about Visual Studio 2015 and all that it brings with it, but you may have to dig down to get to some of the new features that will be instantly of help in your everyday activities.  Here are the five lesser known ones that most interest me&#8230; [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Searching the web there are plenty of articles about Visual Studio 2015 and all that it brings with it, but you may have to dig down to get to some of the new features that will be instantly of help in your everyday activities.  Here are the five lesser known ones that most interest me&#8230;</p>
<h3>Debugging Lambda expressions</h3>
<p>This has been a long time coming. Ever had to debug a long lambda expression only to find you can&#8217;t evaluate it in the Watch windows? Well now you can and more.  <a href="http://www.dirkstrauss.com/programming/debugging-lambda-expressions-in-visual-studio-2015" target="_blank">Dirk Strauss has written a good blog about it here.</a></p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Debug-Lambda.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5090 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Debug-Lambda.png?resize=550%2C362&#038;ssl=1" alt="Debug Lambda Expressions" width="550" height="362" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Debug-Lambda.png?w=550&amp;ssl=1 550w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Debug-Lambda.png?resize=300%2C197&amp;ssl=1 300w" sizes="auto, (max-width: 550px) 100vw, 550px" /></a></p>
<h3>Javascript and HTML Intellisense and Usage Improvements</h3>
<p>Intellisense support has been added for Angular, BootStrap CSS and ARIA in the html editor as well as intellisense for ReactJS, AngularJS, RequireJS and ECMAScript 2015 (aka ECMAScript 6) in the javascript editor.  Oh, let&#8217;s throw in a Json editor too!</p>
<p><a href="http://webtooling.visualstudio.com/frameworks/client-side/" target="_blank">See VisualStudio.com&#8217;s article about the HTML editor intellisense here<br />
</a><br />
<a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Angular-Intellisense.gif?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5091 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Angular-Intellisense.gif?resize=224%2C204&#038;ssl=1" alt="Angular Intellisense in the HTML Editor" width="224" height="204" /></a></p>
<p><a href="http://blogs.msdn.com/b/visualstudio/archive/2015/06/10/javascript-editor-improvements-in-visual-studio-2015.aspx" target="_blank">The Visual Studio blog has more about the javascript intellisense here<br />
</a><br />
<a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ES2015-Intellisense.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5092 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ES2015-Intellisense.png?resize=501%2C180&#038;ssl=1" alt="ES2015 Intellisens in Visual Studio 2015" width="501" height="180" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ES2015-Intellisense.png?w=501&amp;ssl=1 501w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ES2015-Intellisense.png?resize=300%2C108&amp;ssl=1 300w" sizes="auto, (max-width: 501px) 100vw, 501px" /></a></p>
<p>Also, Bower and NPM intellisense, helped by the JSON editor. <a href="http://www.dotnetjalps.com/2015/01/intellisense--bower-and-npm-visualstudio2015.html" target="_blank">Jalpesh Vadgama writes it up in this blog article<br />
</a><br />
<a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/intellisense-for-bower.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5093 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/intellisense-for-bower.png?resize=618%2C458&#038;ssl=1" alt="Bower intellisense in Visual Studio 2015" width="618" height="458" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/intellisense-for-bower.png?w=618&amp;ssl=1 618w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/intellisense-for-bower.png?resize=300%2C222&amp;ssl=1 300w" sizes="auto, (max-width: 618px) 100vw, 618px" /></a></p>
<h3>GIT support improvements and additions</h3>
<p>I tend to work primarily in Visual Studio now when it comes to source control, however I have to switch out occasionally when I need more info (we use <a href="https://www.atlassian.com/software/sourcetree/overview">Atlassian&#8217;s SourceTree</a>). With the new improvements in Visual Studio 2015, I can stay in VS. <a href="https://www.visualstudio.com/en-us/news/vs2015-vs.aspx#VersionControl">VisualStudio.com mention the main features here<br />
</a><br />
<a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/GIT-Branching.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5095 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/GIT-Branching.png?resize=527%2C368&#038;ssl=1" alt="Visual Studio 2015 improves GIT support" width="527" height="368" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/GIT-Branching.png?w=527&amp;ssl=1 527w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/GIT-Branching.png?resize=300%2C209&amp;ssl=1 300w" sizes="auto, (max-width: 527px) 100vw, 527px" /></a></p>
<h3>Enterprise Single Sign On with Azure Active Directory</h3>
<p>If you are creating a website for users that are within your domain and you are using Azure Active Directory you can now add Enterprise Single Sign On at any point in your development by right-clicking on your application and selecting &#8216;Configure Azure AD Authentication&#8217;. This will bring up a wizard that will allow you to the specify the domain from a list of known domains.  The wizard will register your application with that Active Directory and configure your application to prompt for sign-in.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Azure-AD-Sign-In-Wizard.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5096 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Azure-AD-Sign-In-Wizard.png?resize=804%2C551&#038;ssl=1" alt="Visual Studio 2015 Azure AD Sign In WIzard" width="804" height="551" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Azure-AD-Sign-In-Wizard.png?w=804&amp;ssl=1 804w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Azure-AD-Sign-In-Wizard.png?resize=300%2C206&amp;ssl=1 300w" sizes="auto, (max-width: 804px) 100vw, 804px" /></a></p>
<h3>Intellitest &#8211; if you have to support or refactor legacy code with no tests, this will help.</h3>
<p>I suspect this is going to be a bit of a love it or hate it addition. Personally I love it for the reasons below.<br />
Intellitest grew out of Pex, a Microsoft Research Project. It basically boils down to a way of automatically creating Unit Tests for your code that exercise every line (if it is actually possible to exercise every line!). It does this by auto constructing objects that are required parameters for the method under test and then calling that method with many variations of the parameters.  There seems to be a bit of an initial backlash from some quarters as it is definitely NOT a good way to quickly construct Unit Tests as a box ticking exercise for your shiny new project.  However its great strength lies in legacy projects that need to be refactored / upgraded / fiddled with in some way. I have inherited many of these over the years and trying to work out the behaviour of a particularly messy method is never easy.  Now I can point Intellitest at it and make sure my replacement method mimics the results. Note that this is otherwise known as <a href="https://en.wikipedia.org/wiki/Characterization_test">Characterisation Testing</a>.</p>
<p><a href="https://msdn.microsoft.com/en-us/library/dn823749.aspx">MSDN has an article about using Intellitest<br />
</a><br />
<a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Intellitest.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5097 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Intellitest.png?resize=682%2C546&#038;ssl=1" alt="Intellistest in Visual Studio 2015 brings help for legacy software" width="682" height="546" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Intellitest.png?w=682&amp;ssl=1 682w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/Intellitest.png?resize=300%2C240&amp;ssl=1 300w" sizes="auto, (max-width: 682px) 100vw, 682px" /></a></p>
<p>Overall a great set of features that should really help save time. <a href="https://www.cognim.co.uk/more-concise-more-readable-c-6-0-real-world-gains/">You can also see my blog about improvements that came with C# 6.0</a></p>
<p>Have fun!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/5-lesser-known-reasons-to-upgrade-to-visual-studio-2015/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5086</post-id>	</item>
		<item>
		<title>Adding tables of static data to an SSDT project</title>
		<link>https://www.cognim.co.uk/adding-tables-of-static-data-to-an-ssdt-project/</link>
					<comments>https://www.cognim.co.uk/adding-tables-of-static-data-to-an-ssdt-project/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Mon, 15 Sep 2014 15:54:06 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[data warehouse]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/?p=71</guid>

					<description><![CDATA[Quite often when creating a database you will need tables of static data.  These range from simple lookups to date dimensions in a data warehouse.  You can easily create these in an SSDT project. Presuming you have already designed your tables and they are present in your project; Create a folder in your project called [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Quite often when creating a database you will need tables of static data.  These range from simple lookups to date dimensions in a data warehouse.  You can easily create these in an SSDT project.</p>
<p>Presuming you have already designed your tables and they are present in your project;</p>
<ul>
<li>Create a folder in your project called StaticData then add a sql script to generate the data you require, one for each table.  For instance I have a date dimension table called Dim_Date and have created a script called Populate_Dim_Date.sql.<br /> <a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/staticsqlscript.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-full wp-image-76" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/staticsqlscript.png?resize=244%2C258&#038;ssl=1" alt="StaticSQLScript" width="244" height="258" /></a></li>
<li>Next create a script called &#8216;Script.PostDeployment.sql&#8217; in the root of your project by right clicking your project and choosing &#8216;Add&#8217; then &#8216;Script&#8217;<br /> <a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/addscript.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-75" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/addscript.png?resize=300%2C146&#038;ssl=1" alt="AddScript" width="300" height="146" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/addscript.png?w=665&amp;ssl=1 665w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/addscript.png?resize=300%2C147&amp;ssl=1 300w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a><br /> and choosing &#8216;user scripts&#8217; in the SQL Server section, followed by &#8216;Post-Deployment Script&#8217;, then clicking the Add button.<br /> <a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdeploymentscript.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-74" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdeploymentscript.png?resize=300%2C207&#038;ssl=1" alt="PostDeploymentScript" width="300" height="207" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdeploymentscript.png?w=955&amp;ssl=1 955w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdeploymentscript.png?resize=300%2C207&amp;ssl=1 300w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></li>
</ul>
<p>This will create a script that runs following the full deployment of your project and you can direct it to step through each of your sql creation scripts in the StaticData folder we created earlier. To do this you simply add a SQLCMD read command to the post deployment script for each of the sql files you want to execute. Here I have added a command to read (include) the script I created for the date dimension.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdepscript.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-77" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdepscript.png?resize=300%2C135&#038;ssl=1" alt="PostDepScript" width="300" height="135" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdepscript.png?w=776&amp;ssl=1 776w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdepscript.png?resize=300%2C135&amp;ssl=1 300w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>Note that to prevent an infestation of the red squigglies you will need to select the icon that represents placing the editor in SQLCMD Mode, in my image above it is the icon with a blue border.</p>
<p>Now when you publish your project your tables will be populated according to your scripts &#8211; easy peasy!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/adding-tables-of-static-data-to-an-ssdt-project/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">71</post-id>	</item>
		<item>
		<title>Adding database references to a sql server project</title>
		<link>https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/</link>
					<comments>https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Tue, 09 Sep 2014 11:24:33 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/?p=57</guid>

					<description><![CDATA[If you are creating a sql server project with SSDT (see here) and your sql refers to another database you will need to add a database reference to allow the project to build. You can do this by right clicking your references folder and selecting &#8216;Add Database Reference&#8217; If the database you are referring to is [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you are creating a sql server project with SSDT (<a title="Creating a SQL Project from an existing database" href="https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/">see here</a>) and your sql refers to another database you will need to add a database reference to allow the project to build. You can do this by right clicking your references folder and selecting &#8216;Add Database Reference&#8217;</p>
<p><a href="http://makesharp.files.wordpress.com/2014/09/adddatabasereference.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-full wp-image-62" src="http://makesharp.files.wordpress.com/2014/09/adddatabasereference.png?resize=244%2C166" alt="AddDatabaseReference" width="244" height="166" /></a></p>
<p>If the database you are referring to is also a part of the solution &#8211; for instance if you are creating a data warehouse and you have a supporting staging database, it is very similar to the process of adding an external project reference to a c# project. you just need to select &#8216;Database projects in the current solution&#8217; and choose your database from the dropdown list.</p>
<p><a href="http://makesharp.files.wordpress.com/2014/09/database-project-in-the-current-solution.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-63" src="http://makesharp.files.wordpress.com/2014/09/database-project-in-the-current-solution.png?w=300&#038;resize=300%2C93" alt="Database project in the current solution" width="300" height="93" /></a></p>
<p>You can also reference a system database here. Occasionally however you will need to reference a database that is neither of the above.  If the database you need to reference is already a data tier application you can browse for the dacpac but if it is not (for instance it may be a legacy database) you will need to create a data tier application from it first.</p>
<p>To extract a dacpac from an existing database, open the sql server object explorer in Visual Studio, connect to the server, right click the database and choose &#8216;Extract Data-tier application&#8217;.</p>
<p><a href="http://makesharp.files.wordpress.com/2014/09/extract-data-tier-app.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-64" src="http://makesharp.files.wordpress.com/2014/09/extract-data-tier-app.png?w=262&#038;resize=262%2C300" alt="Extract Data Tier app" width="262" height="300" /></a></p>
<p>Choose where to save the dacpac, then select &#8216;Extract Schema Only&#8217; and decide whether you need the additional options such as user login mappings etc. Once you have created the dacpac you can go back to the add database reference dialog and select the dacpac you just created.</p>
<p><strong>Database Location</strong></p>
<p>In the Database Location section of the Add Database Reference dialog set the location of the referenced database e.g. &#8216;Different database, same server&#8217;, the name of the database (should be pre-filled) and whether you want to add a database variable to embed into your sql instead of a hardcoded path.  Finally (and often very importantly!) you may want to check the &#8216;Supress errors caused by unresolved references in the referenced project&#8217; option at the bottom of the dialog.  This is especially useful in legacy databases that themselves reference other databases.</p>
<p><a href="http://makesharp.files.wordpress.com/2014/09/add-database-reference.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-61" src="http://makesharp.files.wordpress.com/2014/09/add-database-reference.png?w=300&#038;resize=300%2C210" alt="Add Database Reference" width="300" height="210" /></a></p>
<p>After clicking ok you should be good to go. This reference is there just to allow the application to compile, it does not get included in the deployment, but is an excellent way of making sure that your external references are correct.</p>
<p>As a final note, you need to ensure that your references are kept up to date if you are working on a project.  Although you can create a NuGet feed for your created dacpacs, as of Sept 2014 NuGet does not yet support importing to an SSDT project. For now you will have to keep a manual check.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">57</post-id>	</item>
		<item>
		<title>Visual Studio SSDT and TeamCity &#8211; Using Publishing Profiles and TeamCity integration</title>
		<link>https://www.cognim.co.uk/ssdt-using-publishing-profiles-and-teamcity-integration/</link>
					<comments>https://www.cognim.co.uk/ssdt-using-publishing-profiles-and-teamcity-integration/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Fri, 01 Aug 2014 13:02:33 +0000</pubDate>
				<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Team City]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/?p=48</guid>

					<description><![CDATA[Database DevOps &#8211; SSDT and TeamCity Using Visual Studio and SSDT you can immediately publish a fresh database or update an existing one by simply right clicking the database project and choosing &#8216;Publish&#8217;. This will bring up a dialog that lets you edit the connection string to your database and set various options related to the publish. At [&#8230;]]]></description>
										<content:encoded><![CDATA[<h3>Database DevOps &#8211; SSDT and TeamCity</h3>
<p>Using Visual Studio and SSDT you can immediately publish a fresh database or update an existing one by simply right clicking the database project and choosing &#8216;Publish&#8217;. This will bring up a dialog that lets you edit the connection string to your database and set various options related to the publish.<a href="http://makesharp.files.wordpress.com/2014/08/publish.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-53" src="http://makesharp.files.wordpress.com/2014/08/publish.png?w=300&#038;resize=300%2C152" alt="Publish" width="300" height="152" /></a></p>
<p>At this point you have a choice &#8211; whether to register your published database as a Data Tier Application or not. Please do so.  There are two distinct advantages</p>
<ul>
<li>You can enable database drift detection.</li>
<li>You can query the server to see what version database is published there, when and by whom.</li>
</ul>
<p>Registering a database as a Data-Tier Application stores a copy of the current state of the database schema in system metadata tables as well as associated information relating to the publish itself.  To see quick info you can run</p>
<p style="padding-left: 30px;"><span style="font-family: Consolas;"><span style="color: #0000ff; font-family: Consolas; font-size: small;">select</span> <span style="color: #808080; font-size: small;">*</span> <span style="color: #0000ff; font-size: small;">from</span> <span style="color: #008080; font-family: Consolas; font-size: small;">sysdac_instances</span></span></p>
<p>against the msdb database on the server you published to.</p>
<p>Database drift is a very useful feature that allows you to check whether somebody has directly altered the database in some way since the last publish. I know this is a problem for many small teams &#8211; a query is a little slow so an index is added, a default was applied to a column because an app was throwing exceptions further down the pipeline and it had to be fixed quickly. This allows you to detect that, find the changes and if necessary bring them in to your project or else delete them. I always choose the option to block publish when database has drifted from registered version.</p>
<p>Now that you have selected your server, registered the database as a DTA and prevented drift, save the profile in the form .publish.xml. This isn&#8217;t just so that you can double click the profile to immediately publish (although you can of course) this is so that when TeamCity (you ARE using CI aren&#8217;t you?) builds your SSDT solution you can tell it which profile to use to automatically publish your database.  How good is that?</p>
<p>In the TeamCity build step that actually builds your solution you can select a target of &#8216;Build Publish&#8217; and then in your command line parameters add the following</p>
<p>/p:SqlPublishProfilePath=&lt;profilename&gt; /p:DeployOnBuild=true</p>
<p>Where &lt;profilename&gt; is the full name of your profile e.g. myserver.publish.xml.<a href="http://makesharp.files.wordpress.com/2014/08/build.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-54" src="http://makesharp.files.wordpress.com/2014/08/build.png?w=300&#038;resize=300%2C182" alt="Build" width="300" height="182" /></a></p>
<p>Done!  An easily updated, version controlled database that watches for people messing about with it on the server and lets you know.  What more could you ask for?</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/ssdt-using-publishing-profiles-and-teamcity-integration/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">48</post-id>	</item>
		<item>
		<title>Creating a Visual Studio SQL Project from an existing database</title>
		<link>https://www.cognim.co.uk/creating-a-sql-project-from-an-existing-database/</link>
					<comments>https://www.cognim.co.uk/creating-a-sql-project-from-an-existing-database/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Tue, 29 Jul 2014 15:24:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/?p=23</guid>

					<description><![CDATA[There are all sorts of reasons why this is a good idea.  Not least because you can version control, unit test and tie into your CI system any existing database. How many times have you found inconsistencies between a test and live database, not known which one is right and been unsure who to ask [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>There are all sorts of reasons why this is a good idea.  Not least because you can version control, unit test and tie into your CI system any existing database.</p>
<p>How many times have you found inconsistencies between a test and live database, not known which one is right and been unsure who to ask on your team?  In my experience, especially in smaller teams with no DBA, this happens a lot and people do bad things like edit the live database directly (&#8220;Hmmm, according to the query plan I need to add an index.  I&#8217;ll just do that now.&#8221;).</p>
<p>By creating a SQL Server project using SSDT</p>
<ul>
<li>You will know exactly who changed what and when.</li>
<li>You can fail a publish if database drift is detected (ie the database you are publishing to is different from the last time you published because someone changed something directly).</li>
<li>You can create unit tests with standardised data that run against a fresh database.</li>
<li>You can track database refactoring (ie changing a column name) so that tables are not dropped and rebuilt when published.</li>
<li>You can fail a publish if data loss will occur.</li>
<li>You can fully automate deployment to multiple servers and bring them all to a standard level regardless of their current version.</li>
</ul>
<p>So much good stuff!</p>
<h2>Here&#8217;s how you do it.</h2>
<p>First, make sure you have the <a href="http://msdn.microsoft.com/en-us/data/gg427686">latest version of SSDT</a>.</p>
<p><strong>Create the project</strong></p>
<ol>
<li>In Visual Studio, select File / New Project.</li>
<li>Under Templates. click &#8216;SQL Server&#8217; and choose &#8216;SQL Server Database Project&#8217;</li>
<li>Name your project according to the database you are importing and also name your solution, then click OK.<br />
<a href="http://makesharp.files.wordpress.com/2014/07/filenew.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-25" src="http://makesharp.files.wordpress.com/2014/07/filenew.png?w=300&#038;resize=300%2C188" alt="FileNew" width="300" height="188" /></a></li>
</ol>
<p><strong>Import your database</strong></p>
<ol>
<li>Right click the project you just created and select Import, then Database</li>
<li>Select your database from the Source Database Connection dropdown list, or use the New Connection button to add it.</li>
<li>In addition to the default Import Settings that are selected I usually also select &#8216;Import Database Settings&#8217; so that the correct database version is chosen in the project properties. Otherwise you can usually leave everything else as is.<a href="https://makesharp.files.wordpress.com/2014/07/import.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-33" src="http://makesharp.files.wordpress.com/2014/07/import.png?w=300&#038;resize=300%2C257" alt="Import" width="300" height="257" /></a></li>
</ol>
<p><strong>Check your folders and files</strong></p>
<p>At this point you will have a folder structure based on the database schema &#8211; if you only use dbo then you will only see that, otherwise you will see a folder per schema and an additional security folder where sql for creating your schemas has been put. (This is also where you put sql for new schemas)<a href="https://makesharp.files.wordpress.com/2014/07/structure.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-full wp-image-41" src="http://makesharp.files.wordpress.com/2014/07/structure.png?resize=289%2C252" alt="Structure" width="289" height="252" /></a> Here you can see that my database has two schemas &#8211; dbo and IntegrationTest. SSDT also separates out your functions, stored procs and tables. In the Security folder you can see the sql for creating the IntegrationTest schema.</p>
<p>If there is anything missing at this point you may want to check the import settings. You can always delete all the added files and folders and do the import again.</p>
<p><strong>Build and be happy!</strong></p>
<p>Right click your project and select Build.</p>
<ul>
<li>If there are no external references the project will build and create a dacpac. This will be saved in your bin directory in the appropriate configuration folder.</li>
<li>If there are external references required you will need to add them. <a title="Adding database references to a sql server project" href="https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/">I have blogged how to do this here</a>.</li>
</ul>
<p>You can also add static data such as lookup tables or date dimensions and again <a title="Adding tables of static data to an SSDT project" href="https://www.cognim.co.uk/adding-tables-of-static-data-to-an-ssdt-project/">I have blogged about this here</a>.</p>
<p>We are now at a stage where you can version control your database and to publish it to a particular server you just need to right click the project and select &#8216;Publish&#8217;. Note that there are several options when publishing and you can create profiles for different servers.  <a href="https://www.cognim.co.uk/ssdt-using-publishing-profiles-and-teamcity-integration/">I have blogged about how to do that here.</a></p>
<p>Good luck!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/creating-a-sql-project-from-an-existing-database/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">23</post-id>	</item>
		<item>
		<title>Visual Studio SSDT and TeamCity &#8211; What you need to do.</title>
		<link>https://www.cognim.co.uk/ssdt-and-teamcity-what-you-need-to-do/</link>
					<comments>https://www.cognim.co.uk/ssdt-and-teamcity-what-you-need-to-do/#respond</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Mon, 28 Jul 2014 11:44:20 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Team City]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/2014/07/28/ssdt-and-teamcity-what-you-need-to-do/</guid>

					<description><![CDATA[I have just spent the last few days trying to get a SQL Project to build, deploy, run unit tests and create a dacpac on our build server which uses TeamCity. It wasn&#8217;t a simple process and I had to accept a few conditions that I wasn&#8217;t overly keen on but the upshot is that [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I have just spent the last few days trying to get a SQL Project to build, deploy, run unit tests and create a dacpac on our build server which uses TeamCity. It wasn&#8217;t a simple process and I had to accept a few conditions that I wasn&#8217;t overly keen on but the upshot is that it works now and it works well.</p>
<p>Here is the outline of how it all hangs together, I will do a few more detailed posts to follow up.</p>
<p>The solution itself consists of three projects. Two database projects and a unit test project.  They are checked into GIT (using <a href="https://bitbucket.org/">BitBucket</a>) and <a href="http://www.jetbrains.com/teamcity/">TeamCity</a> watches the repository to trigger a build.  The build creates a dacpac for each database, publishes the changes to the appropriate server, runs the unit tests and saves the dacpacs into a nuget package that is <a href="http://confluence.jetbrains.com/display/TCD8/NuGet?_ga=1.7707770.999349697.1405089901">published by TeamCity itself</a>.</p>
<p>Out of the box, TeamCity can handle the build but you need MSTest and SSDT installed on the build server.  That is where your troubles begin.  You can download an MSTest agent as I wrote about <a href="https://www.cognim.co.uk/teamcity-and-msbuild-mstest/">here</a>.  You can even <a href="http://stackoverflow.com/questions/22241295/build-sql-server-data-tools-for-visual-studio-2013-project-on-build-server-wit">install the SSDT tools for VS2012</a> (though that was a bit hit and miss for me). The real problem is that with VS2013 the SSDT tools are integrated and no longer available as a separate download.  In the end I had to settle for installing VS2013 on the build server.  Microsoft allows your developer license to be used on the build server and at least I can easily update the SSDT version &#8211; I&#8217;m not particularly happy about having to do it though.</p>
<p>In order to publish your database to the correct server you just need to include appropriate <a href="http://sqlblog.com/blogs/jamie_thomson/archive/2012/05/09/publish-profile-files-in-sql-server-data-tools-ssdt.aspx">publish profile files </a>and Microsoft have provided the ability in database unit tests to switch config files according to the build server machine name. The publishing part worked fine for me but the config switching seems flaky and if you put a whitespace in the wrong place your config will be ignored.  My workaround here was to resort to <a href="https://www.nuget.org/packages/SlowCheetah/">Slow Cheetah</a> &#8211; a plugin from NuGet that allows config switching for app.config in the same way that you can achieve it with web.config. This works well but remember to restore your nuget packages as the first build step in TeamCity. It&#8217;s not so restrictive as a config that switches based on machine name (we only have a single build server so would be unable to test on multiple platforms).</p>
<p>The result is that on every check in, the dacpacs are built, deployed to a test environment, tested and if they pass, made available via a nuget feed for other projects.</p>
<p>It feels good when it all just starts working!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/ssdt-and-teamcity-what-you-need-to-do/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">20</post-id>	</item>
		<item>
		<title>TeamCity and MSBuild / MSTest</title>
		<link>https://www.cognim.co.uk/teamcity-and-msbuild-mstest/</link>
					<comments>https://www.cognim.co.uk/teamcity-and-msbuild-mstest/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Sat, 26 Jul 2014 10:14:06 +0000</pubDate>
				<category><![CDATA[Team City]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/?p=10</guid>

					<description><![CDATA[If you want to run MSTest on your TeamCity build server, you don't need a full install of Visual Studio.]]></description>
										<content:encoded><![CDATA[<p>TeamCity comes with MSBuild so that you can build your solutions directly by selecting a runner type of MSBuild in the Build Step.  You can also choose the version of Visual Studio your developers use and since TeamCity 8.1, <a href="http://confluence.jetbrains.com/display/TCD8/MSBuild" target="_blank">Build Tools for 2013 are supported too</a>.</p>
<p>However if you need to run MSTest for your unit tests TeamCity recommends you install the full Visual Studio.  If you already have a licence for this then it is ok to install a second copy for your build server, but what if the build server is at a client premises and they don&#8217;t want to buy a license? I came across<a href="http://stackoverflow.com/questions/6926888/visual-studio-required-to-run-mstest-test-on-team-city-build-server/18092272#18092272" target="_blank"> this stack overflow post </a>that pointed me to an MSTest Agent download for 2010. You can download the Agents for Visual Studio 2013 from <a href="http://www.microsoft.com/en-us/download/details.aspx?id=40750" target="_blank">here</a>. All you need is the executable so don&#8217;t install the agent as a service and you don&#8217;t need the controller.</p>
<p>Hope that helps.</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/teamcity-and-msbuild-mstest/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">10</post-id>	</item>
	</channel>
</rss>
