Visual Studio - 预编译 - dotless

发布于 2024-08-19 12:07:19 字数 271 浏览 6 评论 0原文

我想知道是否有办法预编译 *.less 文件(http://www. dotlesscss.org/)与 Visual Studio。

该网站给了我一个 dotless.compiler.exe 但我不知道如何将其连接到 Visual Studio。我正在寻找适用于 Webforms 和 ASP.NET MVC 的解决方案。

I wonder if there is a way to precompile *.less files(http://www.dotlesscss.org/) with visual studio.

The site gives me a dotless.compiler.exe but I am not sure how to hook this up to visual studio. I am looking for a solution for both Webforms and ASP.NET MVC.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

握住你手 2024-08-26 12:07:19

根据您的构建环境,您可以将 dotless.Compiler.exe 作为构建任务启动。

例如,在 Visual Studio 中使用预构建任务(全部 1 行):

$(SolutionDir)Tools\dotLess\dotless.compiler.exe -m 
    $(ProjectDir)content\css\site.less $(ProjectDir)content\css\site.css

宏($(SolutionDir) 等)允许项目和文件位置具有一定的灵活性。无需使用标准 .less 文件,只需在标记中引用新的 .css 文件即可。

Depending on your build environment, you can kick off dotless.Compiler.exe as a build task.

For example, using a Pre-Build task in Visual Studio (all 1 line):

$(SolutionDir)Tools\dotLess\dotless.compiler.exe -m 
    $(ProjectDir)content\css\site.less $(ProjectDir)content\css\site.css

The macros ($(SolutionDir), etc) allow a bit of flexibility to project and file locations. Rather than using the standard .less files, simply reference the new .css files in your markup.

固执像三岁 2024-08-26 12:07:19

所有,

在使用了这里讨论的几乎所有替代方案并且不满意之后,我为 Visual Studio 编写了一个 LessCss 编译器插件。仅当 .less 文件发生更改时,它才会使用 .less 文件并生成 .css 文件。它使用最新最好的 less.js 编译器。

在此处查看其使用情况

下载已签名的扩展。

源代码在这里。

我刚刚将其提交到 VS 扩展库。希望它很快就会出现,但同时请安装(或编译然后安装)并检查它。

All,

After using just about all the alternatives discussed here and not being satisfied, I wrote a LessCss compiler addin for Visual Studio. It takes .less files and generates .css files only when the .less file changes. It uses the latest and greatest less.js compiler.

See it in use here.

Download the signed extension.

Source code is here.

I just submitted it to the VS extension gallery. Hopefully it will be up there soon but in the meantime please install (or compile then install) and check it out.

新人笑 2024-08-26 12:07:19

Phil Haack 来救援:http:// haacked.com/archive/2009/12/02/t4-template-for-less-css.aspx

每当您希望在编译时在解决方案中生成某些内容时,T4 通常是最佳选择。 。

Phil Haack to the rescue: http://haacked.com/archive/2009/12/02/t4-template-for-less-css.aspx

Whenever you want to have something generated in your solution at compile time, T4 is usually the way to go...

时间海 2024-08-26 12:07:19

这是我使用 MSBuild 提出的解决方案。它是增量的,因此只有当 Less 发生变化时才会发生。它还可以正确处理@import

首先,使用 NuGet 将 dotless 添加到您的项目中。您不需要它添加到您的 web.config 中的任何魔力,因此您可以恢复它 - 您只是使用它来获取编译器可执行文件。

接下来,将“根”Less 文件添加到 .csproj 中,如下所示:

<ItemGroup>
    <LessCssRootInput Include="example.less" />
</ItemGroup>

最后,将此代码段添加到 .csproj 的底部:

<ItemGroup>
    <LessCssSubInput Include="**\*.less" Exclude="@(LessCssRootInput)" />
    <LessCssOutput Include="@(LessCssRootInput -> '%(RelativeDir)\%(Filename).css')" />
</ItemGroup>
<Target Name="CompileLessCss" BeforeTargets="Compile" Inputs="@(LessCssRootInput);@(LessCssSubInput)" Outputs="@(LessCssOutput)">
    <Exec Command=""$(SolutionDir)\packages\dotless.1.3.1.0\tool\dotless.compiler.exe" --minify --keep-first-comment @(LessCssRootInput)" />
</Target>

Here's the solution I came up with, using MSBuild. It's incremental, so it should only happen when the Less changes. It also correctly handles @import.

First, add dotless to your project with NuGet. You don't need any of the magic it adds to your web.config, so you can revert that - you're just using it to get the compiler executable.

Next, add your "root" Less files to your .csproj, like so:

<ItemGroup>
    <LessCssRootInput Include="example.less" />
</ItemGroup>

Finally, add this snippet at the bottom of your .csproj:

<ItemGroup>
    <LessCssSubInput Include="**\*.less" Exclude="@(LessCssRootInput)" />
    <LessCssOutput Include="@(LessCssRootInput -> '%(RelativeDir)\%(Filename).css')" />
</ItemGroup>
<Target Name="CompileLessCss" BeforeTargets="Compile" Inputs="@(LessCssRootInput);@(LessCssSubInput)" Outputs="@(LessCssOutput)">
    <Exec Command=""$(SolutionDir)\packages\dotless.1.3.1.0\tool\dotless.compiler.exe" --minify --keep-first-comment @(LessCssRootInput)" />
</Target>
静若繁花 2024-08-26 12:07:19

还有另一种方法可以在开发过程中进行预编译。

dotless 项目具有一个命令行编译器 (dotless.Compiler.exe),可以编译和缩小 CSS。

您还可以使用带有--watch参数的compiler.exe,它将继续运行并扫描您的输入文件以查找更改,并在您对文件进行更改时重新生成。从而使您独立于 Visual Studio。

There is also another way to precompile during development.

The dotless project features a commandline compiler (dotless.Compiler.exe) that can compile and minify the CSS.

You can also use the compiler.exe with the --watch parameter where it will keep running and scan your input file for changes, regenerating whenever you make changes to the file. Thus making you independent from Visual Studio.

智商已欠费 2024-08-26 12:07:19

在我寻找使用 DotLess 的过程中,我还发现了这个库:

http://www.codethinked.com/post/2010/03/17/Bundler-Now-Supports-Css-And-less.aspx

将其添加到我自己的问题中,因为它可能会帮助别人。

In my search for working with DotLess I also found this library:

http://www.codethinked.com/post/2010/03/17/Bundler-Now-Supports-Css-And-less.aspx

Adding it to my own question because it might help others.

南街女流氓 2024-08-26 12:07:19

您可能想看看 Chirpy。它拥有比 LESS 更多的支持。我希望我能在写自己的文章之前找到它。

说到这里,我还编写了一个使用 JS 文件(而不是 .NET 端口)执行的 Visual Studio 自定义构建工具,您可以在此处查看源代码: https://github.com/paultyng/JsBuildTools

或者它也位于 JsBuildTools

You may want to take a look at Chirpy. It has a lot more support than just LESS. I wish I would have found it prior to writing my own.

Speaking of which I also wrote a Visual Studio Custom Build Tool that executes using the JS file (instead of the .NET port) you can take a look at the source here: https://github.com/paultyng/JsBuildTools

Or it is also on the extensions gallery under JsBuildTools.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文