Intellisense with MVC4 Style Bundling

2019-06-15 13:14发布

问题:

So far I can't find a question or fix for this. I'm sure it's something simple I'm missing.

I have a style bundle with a bunch of minified CSS, and I am decorating HTML elements with the classes inside. Everything is working great.

Intellisense and ReSharper however are both bugging me about the CSS the classes being unknown. I'm guessing this is because they cannot peek inside the bundles.

Question: Is there a way to fix this?

<!-- Style Bundles in HEAD tag-->
@Styles.Render("~/bundle/style/css")
@RenderSection("styles", false);

<!-- HTML elements in BODY tag: "row" is an unknown css class -->
<div class="row">
    <p>Lorem ipsum</p>
</div>

Update: Visual Studio 2012. LESS conversion and intellisense works for single directly referenced files. My situation is that intellisense breaks when referencing a LESS bundle.

Update 2: Here's the code showing the BundleConfig.cs since it isnt clear

var customStyles = new Bundle("~/bundle/style/css")
                      .Include("~/Content/normalize.css","~/Content/*.less");
bootstrapStyles.Transforms.Add(new LessTransform());
bootstrapStyles.Transforms.Add(new CssMinify());
bundles.Add(customStyles);

Notice we are using Bundle not StyleBundle which is necessary because we want to specify the LessTransform() class and skip the built in CSS transformer. The LessTransform object is a custom object that simply reads in all the LESS content and concatenates it on a StringBuilder and then calls dotless's converter... out comes a huge CSS string that is minified and returned. The question is why cant VS or ReSharper peek at the returned CSS and help check class styles?

回答1:

Here's a post on jetbrains blog. It's a bit out of date, but Jura went on record stating that there were no plans on supporting LESS (yet).

User:

Are there any plans to support LESS? I don’t care a whole lot about full support, but it would sure be nice if it could at least bring highlighting and code completion support into .less files and have it handle nested rules.

Jura Gorohovsky :

No, no such plans yet. Can you point me to a publicly available project that uses LESS extensively so that we can take a look at it to determine the scope of work?

Link

Late edit: Web WorkBench from Mindscape may provide what some people coming to this thread are looking for. They are very response to bug fixes, and have been making some solid improvements to intellisense in the LESS world.



回答2:

Have you installed the js extension to Visual Studio 2012? Go to Tools | Extensions and Updates and then SDKs if you have many installed.

Don't think the bundling has any affect on your intellisense, I've tried with and without and my intellisense is still there. Ensure you css stylesheet is included in your solution and maybe test with a more specific class, e.g. "onebeatconsumer" instead of "row" (there could be a clash somewhere with this)

If you are using LESS, this could most definitely be your issue as it visual might well not be able to parse LESS syntax as it only generates the full styles at runtime. Does styles in a standard css stylesheet work okay for you?