views:

614

answers:

3

I have a Visual Studio 2008 .NET 3.5 Web forms project that constantly shows warnings for my class tags in the html. I have the CSS file included in the master page with the following link:

<link href="/Css/Site.css" rel="stylesheet" type="text/css" />

The warnings I get are:

The class or CssClass value is not defined.

At run time all is good and everything works as expected but these warnings in VS are getting very annoying. Is there some other way to have this linked in? I don't get any VS intellisense on the html class attributes and when I click the warning and then hover over the class="something" attribute on the html the warnings all disappear. Next time I build all the warnings come back.

Any ideas?

EDIT: The file is in include in the project. I have also tried changing the link to:

<link href="Css/Site.css" rel="stylesheet" type="text/css" />

This gives me intellisense it seems but I still have the warnings...

I have also tried:

<link href="~/Css/Site.css" rel="stylesheet" type="text/css" />

This is seeming to work...

Why would they all work at runtime but each one cause different behavior in VS?

EDIT: So closed and re-open VS, the ~ is still being used but warnings are all back and not going away. So is there anything else I can try? The master page is in the app root, the content pages are in sub directories.

A: 

Is the css file in your visual studio project? I have had similar things happen when the css file is exists physically in the correct place on my machine, but is not referenced in the visual studio project.

If it is not, then adding it to the project should resolve the issue.

Matthew Vines
+3  A: 

Have you tried putting the "~" in your href...

<link href="~/Css/Site.css" rel="stylesheet" type="text/css" />

I've found that sometimes Visual Studio sometimes doesn't know how to map up the paths to the css file, depending on where the master file is and where the web content page is, so adding the ~ to the path helps the referencing to just start at the site root and move forward.

Dillie-O
This worked for a bit... problem came back after reloading the project though and I am using the ~/Css/Site.css
Kelsey
"reloading the project" - I don't quite follow. Did you close the project and open it up again? Or was this after a recompile?
Dillie-O
+3  A: 

Figure it out. I was running Visual Studio 2008 RTM.

The css issue is a bug in RTM that is fixed in SP1.

Link to VS2008 SP1 Patch Notes

317251 - When you link to a .css file in a master page by using the ~/ syntax, child pages cannot access the .css file.

Kelsey
Ahh, good 'ol service pack to the rescue yet again! 8^D Nice catch!
Dillie-O