Visual Studio 2013 only builds HTML changes, not C# changes - c#

I am building a personal website using asp.NET's webforms in visual studio 2013 express for web and am following this tutorial:
http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/introduction-and-overview
My page is structured exactly the same as in the website, I have changed some minor stuff to make it my own but the structure in terms of the C# classes and how the interact with the HTML are exactly the same.
I got to section 5 of the tutorial "Display Data Items and Details" and everything was working fine. I've used git a lot in the past so I decided to create a repository for this project so I can access it at work if I feel like.
Suddenly now when I make changes to the C# classes it won't build. It's even stranger because I if I make a change on an HTML file the change is built. In section 3 of the tutorial we learnt how to make the 'product' classes which are displayed on the products page. If I want to change one of the product names for example, when I build the change is not there. Simultaneously I went and changed some info in the HTML for the contact page, IT CHANGES when I build. Why wont the C# changes take effect when I build any more?
I am relatively new to both asp.NET and visual studio. The HTML changes when I build and the C# does not. When I change either I can see in solution explorer that there is a red tick for pending changes. Why would only the HTML pending change be included in the build and not the C#? How do I ensure that the build is actually building the version I see in my editor window?
EDIT
I do not know if I found the original cause but I found a solution/workaround. I realized that the classes mentioned above were grabbed by the html page from the page's database. The .mdf file for the solution was not being rebuilt whenever I cleaned and built so I physically deleted it and rebuilt the solution and voilla my C# changes occurred. I am still fairly new to this whole thing, can someone explain what the .mdf file does and why it wasn't being rebuilt?

Check your .cs files properties on the properties window in visual studio to make sure their Build Action is set to "Compile", Things that are not set to "Compile" do not get compiled. How MSBuild treats project items depends entirely on their build action. CS files default to "Compile" when you make them, but if you changed them yourself that would be why it doesn't update. Also CS files placed in the App_Start folder default to "Content" and they are compiled by ASP.Net when the Application Starts, so if you changed something in App_Start you need to reset the site.

Not exactly sure what is the problem, but I would do a right mouse click on the solution in Solution Explorer->Clean Solution, then do another build and see if that helps.

Related

Why build action doesn't work in Visual Studio

I work with project written in C#, I use Visual Studio 2019. There are .aspx views in the project. I need to exclude them from build but they should stay in the solution since some tests are linked to them. I use build action: none, according to official documentation that means: The file isn't part of the build in any way. https://learn.microsoft.com/en-us/visualstudio/ide/build-actions?view=vs-2022 . But after the build, when i navigate in browser to these pages - browser starts to download them, which means that they were included into build.
What am I doing wrong? How to exclude these files from the build?
The ASPX files are compiled at run-time from the original location in the source code for local debug/run scenarios (there are no copies for those). From developer's point of view these files already have "Build:none" for local debugging purpose. Changing action to "none" does not in any way impact the original content/location of the file so it will still be located at the same place at the run-time on dev box and render at run-time as if it still built.
Where you'll see an impact of "Build:none" is "published" version of the site - with "none" files will not show up in published version and hence will not work from "published" version.

will it auto compile when a razor page file is updated on server?

Two parts to this question:
1 - when a razor page file (example.cshtml) is updated, will the ASP.NET Core auto compile that file?
2- when a razor page code-behind file (example.cshtml.cs) is updated, will the ASP.NET Core auto compile that file?
I have many web forms that require maintenance and do not want to have to recompile and publish the whole site files every time a single page is updated if we port to Razor Pages.
That depends on your development environment. Assuming you are using Visual Studio as your IDE, usually yes, you will be both able to update your views and code-behind files during a debugging session, if you are running a debug session, and using a debug build (personally, I have never tried to do this in a non-debug build, as I actually see no point in doing so).
I say "usually" because there are some situations which the IDE is not able to update the code which runs behind your app's deployment. Most of the times, if you just alter the code of method bodies in your code-behind files or change some things at your view, things will work smoothly (although you might notice some delay at the first time you reload a page that has been affected by your changes: this is because the IDE is updating your deployment behind the scenes when you reload that page).
However, if you try to do some more complicated things, like editting the signature of methods, declaring new properties in one of your classes, or injecting new stuff in your views, the development environment might have some trouble to update your deploy. Check the screenshot below for a message given by Visual Studio Community 2017 when I try to add a new parameter to a method of a controller I have in one of my projects: the IDE warns me that it won't be able to upload my deployment in the server, and thus my changes won't be correctly reflected during my current debug.
Also, one thing to keep in mind is that Visual Studio mostly will only allow you to make editions to your code when you pause the debug session. Code will be in read-only state if the application is currently running.

Retrieve Only Modified Files After Visual Studio Publish (NB : More of a knowledge gathering)

First of all, i'am not looking for a code sample. I just want some directions on something am working on. I'am an intermediate C# developer and i'am developing something, something like a pet/side project [huh.., it's just a crappy form application :-)].
Currently am working on a ASP.NET MVC Web project. When our client request for a change, we make the change and publish the project, then we we copy only the modified/newly added files(.cshtml, .css, .js etc..) and bin files(.dll) (if there is any controller, model etc change during the development) and replace/add them to the server.
What i'am trying to achieve is, after publishing i run a form app and it list all the projects in TFS, then i can select a project and select any changeset associated with the project(usually the latest one or two changesets) and upon click next it finds the modified/newly created files (.cshtml, .css, .js etc..) and modified(modified on the day of publish) bin files(.dll) and copy to desktop in the same folder structure as publish folder as a single compressed file, it is kind of like automating the 'picking apples (or) files'.
I have almost completed the above however just to know is there any tools for this already available that i'am not aware of or is there some option in VS to perform this? Am just a developer and didn't know the endless possibilities of VS (which i'am excited each day while learning it..)
Also please note i don't want to publish all my files to server directly from VS which i'am already aware of.
[EDIT]
I know simply i can create a batch file to find modified files in a folder and do the needed (my rocket engineering solution above vs simply doing it..!! ). I just want to know is there something already in VS etc...

Visual Studio 2015 build solution does not work

Sorry I am kinda new to C#/.NET and Visual Studio.
The project was built by my supervisor, and I am suppose to make some changes on it. I tried to make some changes on the ModuleController file, but when I click Build Solution, it runs, but it did not affect the website. The controller contain SQL function, even if I make any changes on this file (including delete the entire code), and then refresh the webpage, it can still run the SQL function which has been deleted and output the result.
And when I try to Rebuild Solution or Rebuild Website, I get "circular file references are not allowed". I add batch="false" to Web.config file, it can run, but still get the first problem: the code could not reflect on the webpage.
I have read http://www.gitshah.com/2011/04/how-to-fix-circular-file-references-are.html, but I have checked my folder, there is no ascx files. Only one Global.asax file...
Why is that, is there any possible solutions?
Could anyone helps me? Thanks.

Seeing file changes in the browser without rebuilding your project

I am a Front-end developer, currently working on a .net project. It was explained to me that some of the resources of the project are embedded and when I say some, I mean most of them. Therefor when making changes in the files, you can't see them in the browser without first re-running the project from Visual studio.
I believe you see how this is extremely annoying and frustrating to me. I am used to more dynamic way of working, even have something like livereload running to inject my styles and refresh the page when markup has changes, so I can see the changes in the browser without even switching the active window
I was wondering if there is anything even remotely close to what I am used to as a workflow for web development
Files including aspx and cshtml can be saved (most of the time) and will show changes upon page refresh. Occasionally, the file system may access the files and overwrite them. Files that are compiled upon build are not able to be changed unless a rebuild is issued.
In short terms, front-end is easily edited during run while code-behind and classes cannot.
You've tagged this as MVC, so that means if the view is changed it can be reloaded without running it from Visual Studio. Further, the project just needs rebuilt if you change code. You don't have to re-run it from Visual Studio.
So, in short, you can certainly still make changes in the browser with livereoload, then move those CSS changes to the CSS files in the application, and refresh your browser. That's it.
EDIT: After seeing the screenshot, change that to Content instead of Embedded.

Categories