-
Notifications
You must be signed in to change notification settings - Fork 6
Manual build and installation
This information might be useful only if you want to dive into the NSass source code or use only basic abstractions in your own code. In other cases NuGet packages takes dirty work described below.
NSass tries to play nice with x86/x64 issues. Thanks to Scott Bilas - http://scottbilas.com/blog/automatically-choose-32-or-64-bit-mixed-mode-dlls/. But this approach inflict NSass build process while simplifying it for end-user.
If you want Intellisense/Resharper support for NSass.Core, just build NSass.Wrapper in Win32 or x64 mode. But at the end, you should build NSass.Core in Win32 mode first, then in x64 mode. Or, use Batch Build, which is easier (check both Win32 and x64 configurations for NSass.LibSass and NSass.Wrapper, as well as AnyCPU for NSass.Core).
First of all, you need to reference NSass.Handler or NSass.Core.
Second, to use NSass in your web project without NuGet packages, add the following post-build event to it:
if not exist "$(SolutionDir)$(ProjectName)\bin\NSass.Wrapper\\" mkdir "$(SolutionDir)$(ProjectName)\bin\NSass.Wrapper\\"
del /q "$(SolutionDir)$(ProjectName)\bin\NSass.Wrapper\*.*"
copy "{NSass output directory}\NSass.Wrapper.*.dll" "$(SolutionDir)$(ProjectName)\bin\NSass.Wrapper\\"
copy "{NSass output directory}\NSass.Wrapper.*.pdb" "$(SolutionDir)$(ProjectName)\bin\NSass.Wrapper\\"
where {NSass output directory} should point to NSass binaries directory. Of course, you could use $(SolutionDir) variable and relative paths to keep things clear. To make it working with Publish, include NSass.Wrapper library in project after first build.
If you have web project and just want to process your SASS files at runtime, all you need is this line in Web.config:
<add name="ScssSassHandler" verb="GET" path="*.scss" type="NSass.SassHandler, NSass.Handler, Version=0.0.3.0, Culture=neutral, PublicKeyToken=null" />
Bundling and Minification works as usual with SassBundle:
bundles.Add(new SassBundle("~/bundles/sass").Include("~/Content/Site.scss"));
If you have deeper purpose, follow the next. First of all, create an instance of SassCompiler:
ISassCompiler sassCompiler = new SassCompiler();
Compile regular string with SASS code inside:
string output = sassCompiler.Compile("/* COMMENT */ html { body { color: red; } }");
... or a file:
string output = sassCompiler.CompileFile(@"C:\Site.scss");
If you want to handle SASS compilation errors nice, just catch SassCompileException - message inside contains all the necessary information.