Closed stevenvolckaert closed 3 years ago
I just discovered this behavior manifests itself also when the project is in the legacy, non-SDK-style project format.
So, this issue is unrelated to MSBuild.SDK.SystemWeb
, and I'll close it.
If anyone would have some ideas that could help me convert the CSHTML files in the App_Code
directory, to C# classes for instance, I'd be more than happy to hear about them!
Depends on the complexity of your code. For functions if you don't do anything fancy it could be as simple as copy-pasting into a static function (and add deps as necessary). For helpers you have to replace the razor code with StringBuilder
magic or utilize System.Web.Mvc.TagBuilder
and return an MvcHtmlString
.
Strange thing I also have some helpers in App_Code in one of my projects and it just works, though intellisense is lagging a bit on cold start.
Thanks for your response, @bachratyg.
Perhaps IntelliSense is lagging in our project too - it is a very large project containing around 17.000 files.
Hello!
I'm in the process of migrating one of our ASP.NET projects running in .NET Framework 4.8, to the SDK-style project format. I'm using
MSBuild.SDK.SystemWeb v4.0.47
on Visual Studio v16.9.5.This project has some CSHTML files in the
App_Code
directory; they contain reusable Razor helpers (@helper
declaration) and functions (@function
declaration).When I open an MVC view (also a CSHTML file) which uses one of these helpers or functions, IntelliSense shows an error, saying it cannot find the helper. When I open the CSHTML file that contains the helper code, however, the error disappears.
Also, if I run the ASP.NET compiler (using the
<AspNetCompiler/>
MSBuild task) post-build, it reports no errors.It seems like IntelliSense doesn't load the CSHTML files in the
App_Code
directory until the files are loaded manually. I've declared these files asContent
in the project file as follows:Perhaps these files need some additional properties in the project file (
.csproj
) to be successfully loaded by IntelliSense?Alternatively: Can I declare the Razor helpers and functions in code, instead of in CSHTML? I haven't found out yet how I could do this.
Many thanks in advance for your ideas!