Undeclared variable with LESS #import. What is causing this? Is there a fix? - visual-studio-2012

I have 2 LESS files. Globals.less and Site.less. Globals.less contains all of my global (go figure) variables and an import to a CSS reset definition. Site.less contains the styles in use.
Globals.less:
//Imports
#import "CSSReset.less";
//Colors
#color-background: rgb(0, 0 , 0);
Site.less:
#import "Globals.less";
body {
background: #color-background url('/Images/BackgroundTextureBody.png');
}
The problem is this: In Visual Studio #color-background in Site.less is underlined and the error is "Undeclared variable", but the LESS compiles to CSS just fine and the background color is properly set to #000. It is more of an annoyance than anything, but I lose Intellisense and I get warnings in my error list. I would like the editor to act as expected and be able to "see" my declarations in Globals.less when I am editing Site.less. Am I doing something wrong, is this a bug, or is my environment not setup correctly?

To get intellisense for a particular less file you can add a reference path in the same way you would to get intellisense in a js file.
Example
/// <reference path="Globals.less" />
#import "Globals.less";
body {
background: #color-background url('/Images/BackgroundTextureBody.png');
}

It appears that Visual Studio (or it's LESS interpreter) does not understand the scope of the variable within the imported Globals.less
Importing variables is a normal and common thing to do so I'd suggest that it's a bug or missing feature in your Visual Studio setup.

It turns out that I was using an older version of Web Essentials 2012. The first thing I should have checked and failed to do was to ensure that my environment was up to date. Updating Web Essentials to the latest version corrected the issue.

Related

Can't compile nested less files with Web Compiler 2015

well, I was quite surprised when installing Web Essentials 2015 for Visual Studio 2015 that it didn't include a less compiler anymore:
"Web Essentials 2015 no longer contains features for bundling and minifying of JS, CSS and HTML files as well as compiling LESS".
Everything worked fine before with Visual Studio 2013. So I downloaded Web Compiler 2015, as it is the new compiler from Mads Kristensen. But, after adding all the needed files to be compiled to the compilerconfig.json, I have an error on compilation that it doesn't recognize my variables anymore nor my mixins!
Here's my site.less:
/* Colors and common variables */
#import "Colors";
#import "Variables";
/* Reseting default values for all internet browsers */
#import "Reset.css";
/* BootStrap */
#import "../../../Content/bootstrap/bootstrap.less";
/* Basic mixins */
#import "mixins/Generic_Mixin.less";
#import "mixins/Controls.less";
#import "mixins/Images.less";
#import "mixins/Navigation.less";
#import "mixins/Text.less";
/* Website specific classes */
#import "Controls.less";
#import "Footer.less";
#import "Header.less";
#import "Images.less";
#import "Text.less";
#import "combobox.less";
#import "Sitemaster.less";
And here's one of my many errors :
variable #font-size-base is undefined on line 49 in file
'C:\Users\(...)\Site.WebApp\App_Themes\Default\Styles\mixins\Variables.less':
Please, I don't understand anything to all of this, anyone would have an answer for me ? Thx.
I had the same problem. Web Compiler failed in many ways and the workarounds were messy and wouldn't have been easy to support. Future versions of Web Compiler might be useful, but I came to the conclusion that it's worth the trouble to just switch to a more mature less compiling tool.
This is what worked for me:
Disable Web Compiler
Tools->Extensions and Updates->Installed(search for Web Compiler)->Disable
Then setup Grunt.js by following one of the many tutorials out there. I used this one by Scott Hanselman:
http://www.hanselman.com/blog/IntroducingGulpGruntBowerAndNpmSupportForVisualStudio.aspx
Here's another guide I found very useful:
https://www.orderfactory.com/articles/Bootstrap-LESS-Grunt-VS.html
Since it sounds like you were basically where I was before I followed these instructions, there's a chance you might run into another issue with TypeScript compiling, which Web Compiler turned on by default.
If you get a bunch of "duplicate identifier" errors related to lib.core.d.ts, you may have to disable automatic typescript compiling:
right-click Project->Properties->TypeScript Build->uncheck "Compile on save"
Installing Web Compiler and setting up node tools and assigning an automated task can result in unleashing the ts compiler to run through all the node_modules, looking for things to compile. It can be a mess.
If you want to leave TypeScript compiling on build, you'll need to add a tsconfig.json file to the root of your project to define specific file paths. Without this file, the compiler looks everywhere and you really don't want that. I found it easier to just disable it.
Here's more information on that:
Typescript, confusing "duplicate identifier" error message
Hope this helps.

Visual Studio 2012 Web Essentials 3.7 LESS "variable ... is undefined"

I have VS 2012 Premium Update 4 with the recently released (25 Feb 2014) Web Essentials 3.7 for compiling LESS files.
I'm customizing (Twitter) Bootstrap frontend framework by adding my own custom LESS-files to the compilation process:
I have this folder structure:
main-file.less
bootstrap/
less/
[all bootstrap .less files]
custom/
custom-mixins.less
custom-other.less
custom-variables.less
In main-file.less I have:
#import "bootstrap/less/bootstrap";
#import "bootstrap/custom/custom-variables";
#import "bootstrap/custom/custom-mixins";
#import "bootstrap/custom/custom-other";
It appears to make no difference whether I apply the ".less" extensions in the import directives or not.
When compiling main-files.less, I keep getting errors like:
variable #my-label-color is undefined
variable #grid-gutter-width is undefined
Any ideas for what might be wrong?
Sounds like the import order is incorrect. Find out where those variables are defined and make sure that file is imported before the file where the variables are used.
Update
As correctly stated by seven-phases-max variables can be defined after they are used. Therefore more than likely you are using these two variables without actually assigning a value to them or defining them.
It maybe they are defined in a less file which you have not imported. Check where these variables are defined and ensure they are in main-files.less

Typescript giving "Output Generation Failed" in Visual Studio 2012 with 0.9.5

I've been using Typescript 0.9.5 for the last few days, and then suddenly today the JavaScript files just stopped being generated. I see an error "Output generation failed" in the Visual Studio status bar, but nothing in any of the output windows.
I've rebooted, and restarted Visual Studio, disabled Web Essentials, tried all the usual things.
The files are set as TypescriptCompile in the properties. I've tried adding new files, or editing old ones with no effect. The Project file hasn't been changed as far as I can tell (its in TFS and none of the TypeScript sections have been altered).
I've made sure both files are checked out, still nothing.
Update: I've managed to compile manually using tsc.exe from the command line, so it must be something in Visual Studio.
OK, so I solved the problem.
One of my files contained invalid typescript, specifically trying to export a class when not inside a module. This caused all typescript files to fail to generate, but with no useful error message.
The following file would cause the problem:
export class Test {
public DoSomething() {
}
}
Either removing the export keyword, or adding a wrapping module solved the problem.
I've raised it as an issue here: https://typescript.codeplex.com/workitem/2109
Update: More details.
The above syntax is valid if you are using the CommonJS or AMD module patterns.
To enable this in visual studio you need to edit the .csproj file and insert a new PropertyGroup:
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
If you have an export outside of an internal module Typescript tries to compile it as either commonjs or amd module format. The compilation will fail if the a --module flag is not present on the command line. Use your project properties to set it to the desired value (probably amd in your case).
More info on TypeScript modules : http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

OpenCV 2.0 C++ API using imshow: returns unhandled exception and "bad-flag"

I'm trying to use the new OpenCV 2.0 API in MS Visual C++ 2008 and wrote this simple program:
cv::Mat img1 = cv::imread("image.jpg",1);
cv::namedWindow("My Window", CV_WINDOW_AUTOSIZE);
cv::imshow("My Window", img1);
Visual Studio returnes an unhandled exception and the Console returns:
OpenCV Error: bad flag (parameter or structure field)
(Unrecognized or unsupported array type) in unknown function,
file ..\..\..\..\ocv\opencv\src\cxcore\cxarray.cpp, line 2376
The image is not displayed. Furthermore the window "My Window" has a strange caption: "ÌÌÌÌMy Window", which is not dependent on the name.
The "old" C API using commands like cvLoadImage, cvNamedWindow or cvShowImage works without any problem for the same image file. I tried a lot of different stuff without success.
I appreciate any help here.
Konrad
As I just commented, imread isn't working for me either. A little googling shows other people having the same problem; I guess it's a bug in the library code. For now, here's a hacky workaround:
IplImage* img = cvLoadImage("lena.jpg");
cv::Mat lena(img);
cvReleaseImage(&img);
This way, you can at least use the C++ API for the rest of your stuff.
There's help for this issue.
The solution is, that the usual proposed opencv library files in the linker are not working properly. Instead try to use the debug library files by this:
In Visual C++:
go to Project->Properties (or Alt-F7)
Configuration Properties->Linker->Input->Additional Dependencies
replace the usual
" cv210.lib cxcore210.lib highgui210.lib" by
" cv210d.lib cxcore210d.lib highgui210d.lib" - which are the debugging libraries.
The OpenCv 2.0 API commands should work now.
I had the same problem described above which turns out to be caused by the settings of the linker.
I found the answer in another thread,
OpenCV 2.3 and Visual Studio 2010.
To repeat it here:
Properties of your project (right click on it)
C/C++
General
include directory add the < your directory >\OpenCV2.3\include\opencv2, < your directory >\OpenCV2.3\include\opencv and < your directory >\OpenCV2.3\include
Linker
General
List item
Input
Add all the libs like opencv_core230d.lib opencv_highgui230d.lib and so on...
Once I've done the above, I can run imshow and imread + all other cpp functions seamlessly! OP's problem has probably already been resolved, but hopefully this will be useful to other people who are led here looking for the same solution.
Are you sure you added the whole path starting from /home/.... I had the same problem as you but when I added the whole path, things work out pretty well. The whole path had to be added despite the fact the path exists in the include files.
imread in openCV unlike Matlab does not return an error when file/folder is not found - instead it returns a null matrix, which in turn is reflected as an error during imshow.
Also, imread does not look for image files in the included folders or the workspace. So, specify the entire path whenever possible.
Please take a note of this for future references.
Firstly, you'd better compile your own version OpenCV.
I had the same error with the build (I got from Sourceforge), and solved by compiling my own version in debug and release versions.
And make sure you change the original system env variable PATH to the new build folder build/bin, then you could build and run the imshow() in Debug mode.
I believe this might be related to unicode.
Try the macro _TEXT()
For example:
cv::Mat img1 = cv::imread(_TEXT("image.jpg"),1);
Unicode in Visual C++ 2

Visual C++ 2005: How do I access Win32 form control values in a .cpp file?

I've recently started poking around in Visual Studio 2005, and I'm mucking about in Visual C++. When I double click on a control in the designer, it opens the .h file, which I've understood to be for prototype declarations, and if I put all the guts to the functions in there, I can get my program to work, but I don't like having the code in the .h file.
However, when I put things in a .cpp file, I can't seem to access the controls at all. I get a lot of compiler errors and such, and I'm wondering what VC++ is expecting, as I'm more used to a GCC/MinGW environment.
The errors I receive the most are:
error C2228: left of '.trackBar1/.value/.etc' must have class/struct/union
error C2227: left of '->trackBar1/->Value/->etc' must point to class/struct/union/generic type
I've tried the following to access the control:
Junk::Form1::trackBar1->value
Junk::Form1::trackBar1.value
Junk::Form1->trackBar1
Junk->Form1->trackBar1
this->trackBar1->value //This is legal in the .h file, and how I can get it to work there
trackBar1->value
And a few others that are just attempts out of desperation. I've tried specifying the same namespace and everything as present in the .h file, and I still cannot seem to access the control.
I'm using Visual Studio 2005, with a Visual C++ CLR Win32 form application. The code that Visual Studio uses to create instances of the controls is:
this->trackBar1 = (gcnew System::Windows::Forms::TrackBar());
In Dev-C++ or code::blocks, I'm used to putting the class declarations in the .h file, and then specifying the functions in the .cpp file by doing class::function, but in Visual Studio, I just cannot seem to figure out why I can't do the same, or what I'm doing horribly wrong and stupid.
Thank you.
Thanks for clarifying the question, here's some ideas
Ensure the .h file is included in the corresponding cpp, for example make sure that if you've defined
foo.h
class
{
...
};
be sure that foo.cpp has foo.h included, like this:
#include "foo.h"
... definitions ...
It looks like that within the context of your class that referencing trackBar1 should be valid, that is your last example above. If you are outside of the scope of your class, you will need to declare an instance of the enclosing class and reference its instance of trackBar.
Also, like I said before:
You need to know if your "Form1" is a value or instance of an object or a class or a namespace. If its a namespace/class latter than using :: to clarify the namespace is appropriate. From the error it looks like its likely not a namespace/class/struct. You seem to also be trying to treat it like a pointer. Is it a pointer? How is it newed?
I would simplify to experimenting with an extremely simple C++ header/cpp example. Confirm this works. Slowly copy-paste in your functionality and see at what stage it breaks. Make a hello world program is VS 2005 and add in your code.
When you find where it breaks, and its still broken, edit your question with your simplified set of sample code and we can better help you debug.
This may have happened because the controls were changed (i.e. double clicking). Go back to the control (in design view) and change the name. Then change it back. Then recompile.
Cheers!

Resources