Why I need to Rebuild whole solution when make change in razor cshtml file - razor

I wonder why every time I need to rebuild whole solution when I make changes to .cshtml file to see changes on web. It takes so much time and it is annoying when I just want to check some minor change in html (for example adding <td> element into table which will be filled with value from model)
Please can somebody explain it to me? I'm not very experienced in this area and I want to understand it more :)

Late for the party?
I had the same issue in VS 2019 RC2 while working with out of the oven, still warm demo project based on the Razor Components App template. For each change to take effect I had to rebuild the project. I excluded browser cache issues and everything else I could think of or found mentioned on the web.
I found that in the .csproj file the razor file extensions was set to .cshtml:
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<_RazorComponentInclude>Components\**\*.*cshtml*;</_RazorComponentInclude>
</PropertyGroup>
...while the actual file extensions were .razor. After renaming the .razor files to have .cshtml extension everything worked as expected.
Note, it didn't work the other way around, editing the .csproj file to look for .razor extension because there was a conflict in two stock .target files that I didn't want to touch.

That depends on the change.
If it is a razor change, yes you need to build (compile dlls). If it is not, that you don't.
Razor syntax is a view syntax of c#. It is used in views and transformed into html via the Razor View Engine.
By being C# code, you need to generate it's IL by doing a build or rebuild. Basically you are telling the compiler to generate a new IL based on your changes. Than the web server uses the dlls to run the app.

Related

Why do I need to enable razor runtime compile? Am I taking crazy pills?

As far as I know I've always been able to update cshtml files and immediately see changes (upon refreshing browser) without having to stop my project.
But as I am creating a new project I see this new option to enable this feature and I'm wondering what it is because, after all, I've always been able to do this. But as far as I can tell it does exactly what it says... as if I wasn't able to do this in the past?
But I also notice now that when I make a change to a razor page, it takes a looot longer to see the update as Visual Studio recompiles the project.
What... is... going... on?
As far as I know I've always been able to update cshtml files and
immediately see changes (upon refreshing browser) without having to
stop my project.
Yes.Before asp.net core 3.0,you could do it by default.After asp.net core 3.0,you could install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package to enable runtime compilation.
1.Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.
2.Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:
services.AddControllersWithViews().AddRazorRuntimeCompilation();
Reference:
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0&tabs=visual-studio#enable-runtime-compilation-in-an-existing-project
Update:
From asp.net core 3.1,you could select the Enable Razor runtime compilation checkbox in the Create a new ASP.NET Core web application dialog:

'refactor' move files in VSCode - es6

If I move ComponentFoo.js from folder X to folder Y, than a bunch of import statements break. Looking into this it seems there are many solutions for typescript, but what about js / es6? If I move a file in the editor, it should find all the import statements and update them to the new location. Is this possible?
Old post, but this might help some Googlers. This feature can be enabled and disabled in User Settings. For Javascript and Typescript, it's called "Updated Imports On File Move".
I had apparently disabled it and just figured the feature was broken :X
VS Code has built-in support for this for both javascript and typescript since VS Code 1.24.
For JavaScript specifically, you need to make sure VS code's language support can find all the references to the file so that imports referring symbols in that can be updated properly. Definitely create a jsconfig.json for your project, and also consider enabling semantic checking for JavaScript so that VS Code shows when imports are not being properly resolved
If your project is configured properly but files are not being updated, make sure you are running the latest VS Code insiders build and report an issue if it still doesn't work
for flutter developers you should move files one by one. vscode doesn't support multi file moving with refactor yet.
Just use IntelliJ. It handles all kinds of refactoring perfectly. I'm a huge fan of VS Code, but refacotoring is definetly not one of it's stengths. Some imports don't get detected, and the imports can get modified in a weird way. For example, I had an import like this:
import { myStore} from 'src/common/stores/myStore';
When moving the file of myStore.ts to a different folder, VS Code constructed this bull**it:
import { myStore} from 'src/common/composables/myStoreStore';
The line above is no typo!
Btw I'm using vetur, maybe thats causing it, I don't know ...

Files not under caret on new computer

I opened my project on another computer, and the files where I'd been using a file watcher were expanded, like before they used to be nested like home.scss is now after I run the watcher once on that file.
Is there a way to automatically make all the files be nested?
Because when adding new files and folder with git, it would be quite troublesome to go into each and every file in order to make them become nested.
Like I have some minified JavaScript files that used to be nested, but now is expanded for some reason.
Hope you understand. Thank you.
Edit: Nested***
Is there a way to automatically make all the files go under a caret like that?
Unfortunately not. Such nesting information (to "go under a caret" as you are saying) is taken from "Output path to refresh" field of the corresponding File Watcher.
You have to run file watcher for such files at least once in order to see files nested like you have it on your another computer.
Here is how you can run File Watchers manually without the need to modify those files (so no extra history will appear in your git (or whatever VCS you may be using there)).
https://stackoverflow.com/a/20012655/783119
P.S.
In PhpStorm 2016.3 (the next version that will be released in 1.5-2 months or so) such nesting will be done automatically (the most common combinations) so there will be no need to have File Watchers for providing such info.
If you wish -- you can try EAP build right now (EAP means Early Access Program .. which is sort of Alpha/Beta builds (simply speaking).. and therefore some bugs for new functionality might be present and performance may not be optimal).

Xcode Couldn't Generate Swift Representation for my own framework

I have created a framework which I want to use in my OS X app. Since updating to Xcode 7 on El Capitan, when I try to command-click on the import statement, Xcode goes to the following view.
How can I get Xcode to display the Swift representation properly?
I've had it happen before, and my solution was to recreate every project file which I don't want to do again.
From my experience there are two possible causes for this issue.
The first one is that your framework can't be located. To fix this you need to go to target's Build Settings and add a path to Framework Search Paths either an absolute:
/Users/{user}/path-to-framework-parent-directory
or relative to project directory:
$(PROJECT_DIR)/path-to-framework-parent-directory
Another possible cause is that the path to your framework contains a space in it. I found that it doesn't matter whether you try to escape it with backslash ../Project\ Name/frameworks or take the whole path in double-quotes "../Project Name/frameworks". The result would be that SourceKit could not load the module.
Note that $(PROJECT_DIR) could expand to a path with a space in it and it would too result in the same error. So it looks like a bug in Xcode/SourceKit (I tried the latest Xcode 7.2-beta3 and the bug is still there).
My repository was on the second hard drive /Voluems/Macintosh HD/Repos. I just renamed the hard drive to HD, so the path looks like /Volumes/HD/Repos and the problem was gone.
Max S. answer pointed me in the right direction, however I was using the 'recursive' option for my framework path.
To get things to work I had to explicitly add a path to directly the framework in question's immediate parent directoy (as oposed to just having a path to one of its higher up directories with the 'recursive' option set).
HTH
I had this problem too and the other solutions didn't work. I finally figured it out in my case:
The target name cannot have a space in it either
To rename it:
Go to your project settings
Expand the target list column on the left if not already there
Click on the relevant target once (or press Enter or Tab when having it selected) and type in the new name without the space
Weirdly, just changing the name of my folder from 'Developer' to 'Development' fixed the issue from me.
Running Product->Clean, Product->Build is what worked for me.
In my case, I have created a framework for my SDK along with podspec for making it cocoa pod.
I had the same problem when i use my SDK and it fixed when I imported Foundation API to the file where I am consuming my SDK
import Foundation
Here is another potential solution - one that worked for me:
After importing the framework I never built for simulator, only for real devices. Swift Modules were not showing up, same error. Then I built for Simulator and it suddenly worked, I could see the Swift Modules.
The reason is that when I make my framework, I have a step that copies the swift modules from the iphonesimulator build to the universal build, but does nothing with the modules from the iphoneos build. So my guess is that this is why it didn't work.
Note: once I selected simulator and built it started working all the time, regardless of the build destination.

How to setup limeJS in a totally offline workspace

I'm trying to setup limeJS, the issue is the Internet connection is a problem. I had closure library, box2d, closure compiler and closure templates downloaded separately as .rar files, but I can't find a guide anywhere to set it up like this, everyone just uses(and with reason!!!) the python bin/lime.py init command to get it working. I managed to figure out(yay!) how to setup box2d and closure library but what about the other two?
My laptop is running 64 bits Windows 7. Any help appreciated
All I need is an advice on directory structure, like where to drop the compiler.jar and soy templates .js files, so that when I run the update/create command it doesn't try to download the compiler or templates like it does right now.
I got it working, after taking a quick look at the lime.py file it told me everything I needed, for example both the SoyJs templates file and the compiler need to be in the /path/to/lime/bin/external folder and for example, the lime.py file was expecting a compiler file named compiler-dateOfLatestCompiler.jar instead of compiler.jar.
In general, If you have LimeJS built up in one machine using Python and all, you can just copy paste the whole package anywhere you want and use it just as ususal.
You don't need network once you have all the files/codes for Lime is downloaded.
Infact, you dont even need python for normal development tasks(Python is required to build your js file once you complete development though)