71

How can I use the Sass CSS preprocessor in Visual Studio 2013? Are there any extensions that provide support for Sass?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Hamed mayahian
  • 2,465
  • 6
  • 27
  • 49
  • take a look [here](http://www.hanselman.com/blog/coffeescriptsassandlesssupportforvisualstudioandaspnetwiththemindscapewebworkbench.aspx) – Sirwan Afifi Dec 22 '13 at 07:26
  • 7
    SASS support has [been announced for VS2013 Update 2](http://blogs.msdn.com/b/webdev/archive/2014/02/25/announcing-new-web-features-in-visual-studio-2013-update-2-ctp2.aspx), which is in Community Tech Preview at the time of writing. – Zhaph - Ben Duguid Apr 02 '14 at 14:48
  • 4
    In case you are wondering, this question is being [discussed](http://meta.stackoverflow.com/q/326981/692942) on [meta]. – user692942 Jun 29 '16 at 08:47

11 Answers11

86

Visual Studio 2013 Update 2

Visual Studio 2013 Update 2 has native syntax support for both SCSS and LESS files. You can create SCSS or LESS files and see syntax highlighting and intellisense for these file types. It does not however provide a method of compilation.

Here's a link to the blog explaining about the new features:

We added LESS in VS2013 RTM, and we now have a SASS project item and editor. SASS editor features are comparable to LESS editor, include colorization, variable and Mixins IntelliSense, comment/uncomment, quick info, formatting, syntax validation, outlining, goto definition, color picker, tools option setting etc.

Please note: This update seems to support the newer SassyCSS syntax only. I've tried getting it to work with the older indented SASS syntax without any success.

Compilation

  • Web Essentials. This is a great tool which does all the 'grunt' work for you. Newer versions of Web Essentials are available for Visual Studio 2013 Update 3, 4 and 5.
  • Another free one that just handles compilation is CompileSASS this also works in VS2015.
  • Alternatively you could use MindScape's WebWorkbench, which is a great tool with lots of nice features. There is a free version which does just about enough to get by but there is also a paid version which is far more comprehensive (but in my opinion a little too expensive considering there is a better free alternative).

Visual Studio 2015

For those of you moving to Visual Studio 2015, unfortunately there is still no native support for SASS and LESS compilation. And unfortunately Web Essentials will no longer be supporting compilation either. The author of Web Essentials (Mads Kristensen) explains the reason for this decision here.

Here are a list of extensions that can handle compilation:

WebCompiler (FREE)

Mads Kristensen (the author of web essentials) has created a standalone compilation tool called Web Compiler. All you have to do is install it, then right click on any of the SASS files you want to compile and select Web Compiler > Compile File. From that point on it is watched and anytime it is saved, the file will be compiled.

Download Web Compiler

CompileSASS (FREE)

Similar to Web Compiler this is a standalone extension that was created to work in both VS2013 and VS2015 because compilation was removed from the popular Web Essentials extension. It's lightweight and does the job very well with great error reporting. Read the author's blog about the extension here.

Download Compile SASS

Web Workbench (FREE/PAID)

Mindscape's Web Workbench was my favourite extension for many years when compiling SASS but I have since moved away in favour of the free alternatives. Still, the Pro version is a powerful tool with many ways to customise the outputted files but it is also quite expensive ($39) considering there are free tools out there.

Download Web WorkBench


Visual Studio Code

Same deal as above really, it has native support for SASS and LESS through syntax highlighting and Intellisense but lacks compilation.

Any of the compilers outlined above will work but if you wanted to set up compilation manually here is a brilliant guide:

https://code.visualstudio.com/Docs/languages/css

Community
  • 1
  • 1
Chris Spittles
  • 15,023
  • 10
  • 61
  • 85
  • 4
    Are you sure it supports SASS? From what I can tell VS2013Update2 only supports SCSS syntax and compilation – PW Kad May 29 '14 at 15:33
  • 1
    I agree, it looks like VS 2013 update 2 might only supports SCSS (Sassy CSS). However it's worth noting for the Sass (Syntactically Awesome StyleSheets) beginners, that SCSS is a syntax (the newest) for using Sass. So Sass is supported but maybe only the newer SCSS syntaxt and not the older "Sass syntax". – Ola Karlsson Jun 02 '14 at 08:26
  • 3
    I've created a test project and created a file using the .SASS extension (for the old syntax) and it doesn't recognise it, and it doesn't apply syntax highlighting. I've tried using the SASS syntax in an SCSS file, this time I get compilation errors. It doesn't look like it supports the old SASS Syntax, but it definetly supports the newer Sassy CSS. – Chris Spittles Jun 02 '14 at 09:32
  • @PWKad It doesn't appear to support compilation.You still need a third party plugin for this – geedubb Feb 19 '15 at 11:42
  • The question refers to VS2013 and SASS transpiler is still available for the Web Essentials 2013 version. I believe they removed it only for the 2015 version. – pauloya Nov 05 '15 at 09:27
  • 1
    I tried for an hour to get the old SASS (as opposed to the new SassyCSS syntax) to compile with no luck. One thing that helped me was this site http://www.sasstoscss.com/ where I converted the code to the newer syntax. I wish at least one the plugins would still support the old syntax. – Dan M Mar 02 '16 at 02:42
  • Web Essentials would be an awesome solution if it had more than one error message for every error: "Something went wrong reaching: http://localhost.:". It won't work with my SASS project that compiles fine with Ruby and since it doesn't give a useful message, it's useless. Very disappointed. – xr280xr Mar 17 '16 at 16:29
53

For anyone else looking for an answer to this, I'm posting to save you time as some of the answers are a little out of date.

Whilst working on a small web project in Visual Studio 2013, I wanted to use SASS for the first time. I did some digging and discovered VS 2013 Update 2 was released with native support for SASS (.scss) files.

After a bit more digging, and with no experience of using SASS, I installed Web Essentials 2013 for Update 2 that is used to compile and generate the corresponding .css files.

Even still, I wasn't clear on how it all tied together, but this blog post did a great job of explaining everything for a first timer.

Snippets From Blog (Credit to @akatakritos)

  1. Visual Studio 2013 provides the ability to add SASS files (.scss)
  2. Install Web Essentials 2013 for Update 2
  3. Add a new .scss file to your project, e.g. styles.scss
  4. Update styles.scss, save, and it will auto generate a styles.css file under the .scss file
  5. You can then bundle or link it like a regular .css file

UPDATE July 2015:

In a later Web Essentials update, namely: Version 2.5 for Update 4 Nov 12. 2014, the SASS compiler has been removed.

Alternate compilers:

Tanner
  • 22,205
  • 9
  • 65
  • 83
  • @akatakritos just to let you know I linked your blog to this post. – Tanner Aug 08 '14 at 21:28
  • how do you handle folder structures where mixins and other more componentized scss files exist, but all compile into the main scss, using the VS2013+WebEssentials support? – Thiago Silva Dec 03 '14 at 03:38
  • If you need to use multiple component files that are pulled into a main.scss file you can use SCSS partials. To create a partial, simply give the file name an underscore. Example: _buttons.scss and then in your main.scss file you would import it. Example: import "components/_buttons"; – Hughes Jan 23 '15 at 17:59
  • I don't understand the need to use Web Essentials in this process if there is native support in VS 2013 Update 2 – GôTô Feb 23 '15 at 08:43
  • @GôTô web essentials allows you to view compiled css in a second pane and also re-compiles it every time it saves. Have a read of the linked blog post. There is a chance this answer itself might be outdated now, so i'll check and update if that's the case. – Tanner Feb 23 '15 at 09:01
  • 2
    Web essentials is not working for me. Sometimes it works, sometimes it seems like there are SCSS compilation errors, but it shows no messages. – Ethan Reesor Apr 13 '15 at 22:13
  • Please update your answer, as WebEssentials from version 2.5 does not contain SASS compiler anymore. – Paweł Mach Jul 22 '15 at 07:34
  • 2
    Web Essentials for VS2013 supports SASS transpilation. I'm using the latest version 2.6.36. I believe the support was dropped only for the 2015 version. – pauloya Nov 05 '15 at 09:43
  • @pauloya i'll look in to this later and update as required. – Tanner Nov 05 '15 at 09:45
  • 1
    Using VS2015, Enterprise edition, in order for me to get this all working, I had to first download and install [https://visualstudiogallery.msdn.microsoft.com/6edc26d4-47d8-4987-82ee-7c820d79be1d] and then [https://visualstudiogallery.msdn.microsoft.com/3b329021-cd7a-4a01-86fc-714c2d05bb6c] Story: Then I had to restart VS2015, and it worked. Originally, after downloading Web Compiler, through NuGet Package Manager, restarting VS2015, it failed to load/work or add the "compilerconfig.json" to the root of my project. After downloading and installing Web Analyzer, it worked. Same author... – Eric Milliot-Martinez Feb 08 '16 at 19:53
12

I haven't used Chripy but there are a couple of other options you can try too.

  1. My favorite extension for working with Sass in Visual Studio is Mindscape's Web Workbench. It's well integrated, works with Visual Studio 2013 and it even supports Compass. If you use Less or CoffeeScript it will take care of those as well. I've chatted with one of the developers too and he was really responsive and friendly which is a huge plus in my book. Oh, and I hear more cool things are in the works too.
  2. SassyStudio is another possibility but it didn't seem as powerful as Web Workbench when I tried it.
  3. It isn't out yet but keep an eye on Web Essentials. At the moment it only supports LESS in terms of CSS preprocessors but Sass support has gotten a ton of requests and the program manager replied that "Development underway full throttle." Hopefully soon!

The last option and the one I fall back on a lot of time is just using an external tool watch my SASS files, compile them in the background and let Visual Studio reload the CSS files as they're compiled.

Installing Ruby and SASS via command line and telling it to watch your project directory for changes works fine — but I adore Prepros for this kind of thing.

I haven't tried them all but Scout, Koala, LiveReload, Compass.app and Fire.app are also similar options.

While these aren't always the right solutions for every project they give you a lot of flexibility and maturity that you won't necessarily find in Visual Studio extensions yet.

I hope that helps!

Christin White
  • 489
  • 4
  • 12
  • 6
    As of March 2014: This is now included in Web Essentials VS2013 Update 2 CTP 2 – nitech Jul 03 '14 at 06:25
  • I really liked the Mindscape offering.. but with my new pc install underway, I may try the Web Essentials. – Ads Jan 27 '15 at 13:14
  • I installed Ruby and some auto-processing tool for my sass files when I did a little bit of Sencha Touch work a while back, but I didn't really like it. It was decent at the time and it worked, but I like to have all my dev done in one place. VS is such a nice environment to work in, so why use an external processing tool. Plus if you don't need Ruby for anything else, why install it. – Ads Jan 27 '15 at 13:17
  • If you really like Visual Studio than definitely stick to integrated solutions, especially now that the options have really matured. I however am not a huge fan of VS so I only use it when I absolutely have to, I'd rather use an external solution and Sublime Text. – Christin White Jan 28 '15 at 18:39
5

To compile SCSS in Visual studio, install the CompileSass Visual Studio Extension.

Unfortunately Web Essentials isn't going to support compiling Sass anymore.

I thought this was pretty sad because it was absolutely the simplest way to compile Sass from Visual Studio. I created a new Visual Studio extension that behaves the same way. You just install the extension and it will automatically compile .scss files to compressed .min.css files when you save.

Check out CompileSass.

Greg Gum
  • 33,478
  • 39
  • 162
  • 233
Sam Rueby
  • 5,914
  • 6
  • 36
  • 52
  • From my understanding it will still support compiling Sass, it was just be using Visual Studio's compiler instead? – Joseph Woodward Mar 12 '15 at 11:47
  • I don't think so. The author of Web Essentials (Mads Kristensen) works for Microsoft, and his recommendation is to switch to Grunt/Gulp, which use its tools to compile Sass (Ruby, right?). So the extension above provides the ability to compile Sass with no other dependencies. – Sam Rueby Mar 12 '15 at 12:06
  • This is by far the best answer to how to compile SCSS in Visual Studio. The extension works great and is very easy to install. – Greg Gum Jul 08 '15 at 20:45
3

for ASP.NET there is a couple of ways to do integrate with SASS. Chripy is a common plug-in this is something you want to install in visual studio as an extension.
and thus design time compilation , you can find out more about chripy in http://chirpy.codeplex.com/ ,
as well as there is another package you can install via Nuget :

install-package SassAndCoffee
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110
2

I wrote a blog post on this topic that I feel may help others. Basically SCSS is supported but not the SASS extension.

http://pwkad.wordpress.com/2014/05/30/using-scss-in-visual-studio-2013-with-web-essentials-starring-compass-and-susy/

Also be careful as I have run in to a few problems compiling Compass such as in the compass/css3/images file there were breaking errors.

PW Kad
  • 14,953
  • 7
  • 49
  • 82
  • Have you been able to resolve the Compass problems? Also, have you tried integrating Bourbon, and if so, how well does it work? – Jason Frank Apr 22 '15 at 18:53
1

My comment is probably useless as people may already have an answer, but Scout is available for windows :), I have been using in my projects since March 2013.

You could use Mixture, really powerful and creates minified version of your CSS and JS files.

1

I think the Web Essentials extension - which I'd assume every web dev is running and is sort of a precursor to native VS IDE support - has SCSS compilation support, but I think it only works with VS2013 Update 2 which is in CTP still at this time.

Luke Puplett
  • 42,091
  • 47
  • 181
  • 266
0

Last version of Visual Studio + last version of Web Essentials http://vswebessentials.com/download allows to use Sass and Less out of the box.

Arif Dewi
  • 2,222
  • 26
  • 14
0

If you have MVC 6, you could just use gulp. Original source here: http://developer.telerik.com/featured/css-preprocessing-with-visual-studio/

Add the NPM dependencies in package.json:

{
  "name": "ASP.NET",
  "version": "0.0.0",
  "devDependencies": {
    "gulp": "3.8.11",
    ...
    "gulp-sass": "2.2.0",
  },
  "dependencies": {
    "gulp-sass": "^2.2.0"
  }
}

Then in gulpfile.js:

var gulp = require("gulp"),
    ...
    sass = require("gulp-sass");


paths.js = paths.webroot + "js/**/*.js";
...
paths.sass = paths.webroot + "css/**/*.scss";
paths.cssOutput = paths.webroot + "css";


gulp.task('sass', function () {
    gulp.src(paths.sass)
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest(paths.cssOutput));
});

Finally, in the Task Runner Explorer, right-click on your new task sass then Bindings then select After Build

Serj Sagan
  • 28,927
  • 17
  • 154
  • 183
-3

In Visual Studio 2013 SP 4 there is no problem adding a SCSS file and syncing on every save. I got confused when syncing failed, I found the problem was using a variable before it was defined. The SCSS file doesn't show any error but sync fails.

This works for sync:

$body-main: 45px;
body {
    padding-top: $body-main + 25px;
    padding-bottom: $body-main - 5px;
}

This doesn't work for sync

body {
    padding-top: $body-main + 25px;
    padding-bottom: $body-main - 5px;
}
$body-main: 45px;

In the second case there are no errors and intellisense works, but sync fails.

user2584621
  • 2,305
  • 2
  • 15
  • 9
  • How does this relate to configuring Visual Studio so that it can compile Sass (which is what the question is asking)? – cimmanon Feb 19 '15 at 11:58
  • This is not about compiling sass in visual studio, it seems be repeat of question! – QMaster Aug 18 '16 at 21:00