How to update an asp.net website (just changed files) - asp.net

I am developing an asp.net website that will need regular updates for source codes and HTML sides. After i have completed the necessary updates, i use the 'publish website tool' and publish the site to my local directory. Then i upload all files to Remote File. Is there any way to fix my site with just changed files. For example if i have updated just 2 files of 84 (HTML or source side), is it possible to update just this 2 files without any problem?

While Visual Studio does offer a few different compiling/build options, I think that you are probably doing everything just fine for a Visual Studio Website project. When I'm working with a website rather than a web application, I will only FTP the files that have changed. For example, if I were to change some HTML tags around within an .aspx page, then only that page would need to be uploaded to the web server. If I change the Page_Load function in the .aspx.cs page, then I will definitely need to get the updated DLL on the web server as well.
I use FileZilla for my FTP tool and there is an option to only upload the changed files. So after you use visual studio to publish your website, you can grab the entire contents of that directory and drag it over to the FTP server location and only update what has changed.

The ASP.NET website project offers an option in the Project properties -> "MSBuild Options" tabpage where you can set "Allow this precompiled site to be updatable".
Setting this option
"Specifies that the content of .aspx
pages are not compiled into an
assembly; instead, the markup is left
as-is, allowing you to change HTML and
client-side functionality after
precompiling the Web site. Selecting
this check box is equivalent to adding
the -u option to the
aspnet_compiler.exe command."
according to the docs.

I've been entirely underwhelmed by the available tools to VStudio. And am instead using Gulp.
Even in 2017 the problem remains.
With gulp you can "watch" directories for changed files, so I have it configured to watch the [bin] folder, along with assets separate from aspx/cshtml files.
That way whenever I change anything, it is instantly copied to my publish folder where I can later zip it up and deploy ONLY the changeset. The script even has a delay so I can delay the copy/upload in situations like bundles where they are generated dynamically and take some time to be fully modified.
The only thing I have to do is clean it up before I start my next milestone, so that the "publish" folder which gulp "auto deploys" to is empty and ready for the next run. Emptying a folder and running "gulp watch" in background seems like a small price to pay for such a needed feature.
I feel like this should be a good item to develop as a vstudio plugin.

Recently I have been forced to move to a windows/C#/.NET/MVC environment from linux/node/angular. Sigh. I found the following solution (next paragraph) elminates the pain caused when using visual studio to "publish" the code. The VS2017 publish process copies every file in the entire application to the web server, even if just one character is changed in one file. This can take over an hour for our moderately sized app.
So here's what I do. I first publish the solution locally (typically to bin/release/Publish/). That takes about 1 minute as opposed to 1 hour to publish to the server. Then, I compare the files between my local Publish directory and the server directory using FreeFileSync. FreeFileSync is amazing -- and free. I have access to the server directory via a windows file share. The compare takes about 15 minutes. I can then see exactly what files are different and need to be pushed. Note, the option I use compares the actual CONTENT of the files, not just the create time. I then use the FreeFileSync sync feature (mirror option) to copy the few files needed to the server. This takes maybe two minutes. So the total operation takes about 20% the time Visual Studio "Publish" takes. But best of all, the actual hit on the prod server is only the two minutes it takes to copy the diff files, rather than the 1 hour outage inflicted by Visual Studio Publish as it slogs along copying each and every file.

It depends on the type of project.
If is a project created with File > New Web Site then is ok to just copy the changed .aspx files (make sure that the corresponding code - .cs - files are also copied).
If the project was created with File > New Project > ASP.NET Web Application then you will need to copy the .aspx files and the compiled project dll (by default the dll has the same name as the project like TestProject.dll) from the bin folder inside the project.

i think you need something http://winmerge.org/
where it will compare files that are changed and upload them.
hope this helps

Related

Is it a bad idea for my solution and project to be stored in separate locations?

Somehow my solution and project differ as to their Path/FullPath.
The Path property of my solution ("customerreportingnet") is:
C:\Users\cshannon\Documents\Visual Studio 2013\Projects\customerreportingnet\customerreportingnet.sln
The only project beneath that solution is a Website ("http://localhost/EMS/customerreportingnet/").
The website project's FullPath is this:
C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet
Why would the solution and project location differ?
Did I do something wrong in the setup? I downloaded the files from a .zip file, and extracted them to C:\EnhancedMonthlySalesReporting\
I then created a Virtual Directory in IIS, mapped it to C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet, giving it the Alias "EMS".
Then in VS I open the website (solution/project) this way:
File > Open Website...
and then I open IIS > EMS
When I do this, I do not see any files beneath the "project" - all that's visible in the Solution Explorer are just the solution and project names - no subfolders or files beneath them. But when I right-click the solution "customerreportingnet" and select "Open Web Site", then reply OK to "Open the Web site (this will close the current solution)" all is relatively well - I can right-click the project ("http://localhost/EMS/customerreportingnet/"), select View in Browser (Internet Explorer) and the site runs.
The only files in C:\Users\cshannon\Documents\Visual Studio 2013\Projects\customerreportingnet\ are:
customerreportingnet.sln
customerreportingnet.v12.suo
C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet has those files and many more (as well as beaucoup folders).
Should I try to reset the solution Path to C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet, or is that just an oddity, but not a problem?
If so, is that as easy as just changing that property value, or will that mess things up?
Is it a bad idea for my solution and project to be stored in separate
locations?
A solution is a "container" for projects. Where they are in your local file system doesn't really matter. So in that context, it's "fine".
It's not unusual to have some solution context that is composed of some "projects you did before". So you can "organize" a "new" solution composed of projects located elsewhere (from some other "solution") along with new items.
However, once you get into Source Control, whether it's TFS or GIT, then it will matter - they (projects in a solution) have to be in the same parent folder to be handled easily. So in that context, it's "bad".
TLDR; there are still ways to effectively source control "projects in different folders" - each one is it's own separate "repository". But you'll have to manually/separately do your syncing, merging, etc.
If I'm following your post correctly, I think what you're looking for is Add..., not Open... - you want to add an existing project or web site to a Solution.
Depending on what you're after, and what files you're dealing with:
if you have a Project in the zipped file, then you can Add Existing Project, and so on...
Unsure why you needed to do what you did in IIS - you can do debugging within Visual Studio (IIS Express).
Alternatively, you can Publish your web site/application from Visual Studio and target a local file system folder that you can then set in IIS (Local IIS if installed) - this way, you sort of have a "dev" (VS) and "staging" (publish folder mapped in IIS) environment in your local machine.
Hth...
After you extracted your code and opened the project in visual studio.
Visual studio will automatically create a solution file if you open a project (you can also open a solution file directly). Once you click save all or save your solution file it will save it to the previous location or to the default location.
Since you did not save the file before, visual studio will save it to the default location:
C:\Users\cshannon\Documents\Visual Studio 2013\Projects\[ProjName]\[ProjName].sln
If you want other developers to be easily able to open your project. (especially when you start to have multiple projects inside 1 solution), you want to include the solution file inside the project location. Otherwise every developer has to create this solution file himself, which is annoying and cumbersome work.
Since dotnet core the best practice file structure is this:
/root
/src <== contians all the projects per folder
/project1
/project1.csproj
/etc*
/project2
/[ANameForSolution].sln (so directly inside the proj folder, next to src)
The old habit people use was more flat:
/root
/project1
/project2
/YourSolution.sln
The best practice, moving everything to /src is because lately a root of the project already has a lot of (config) files, and this way you can keep the root a bit cleaner.

ASP.NET 3.5 cannot see my code behinds

I am developing a piece of an existing web site and am having numerous issues trying to upload my files to the server. Everything runs fine locally, but once I put my files on the server things start breaking.
Right now I have a page that gets this error
"Parser Error Message: Could not load type '[Namespace].[PageName]'
. If I take out the inherits statement, it works. The namespace and the pagename are declared in the code behind, which is referenced in the page header.
I also just noticed that all of the pages that predate me don't have code behinds.
There are two options for putting a file on a web server.
One option is to compile it and use a "Publish" feature, in which all of your code-behind files are NOT on the server, and are instead are compiled down to the .dll.
Another is to not compile the site, and simply copy all the aspx ans .cs (or .vb) files out there, uncompiled.
Actually there are three, but I think you only need to deal with these two right now. They are described further at http://msdn.microsoft.com/en-us/library/ms178466(v=vs.100).aspx under the "Flexible Deployment" section.
Your predecessor apparently used the first method. The only way to fix this is to get the compiled .dll files out of the \bin directory, and decompile them using a tool like Reflector or Teleriks's Just Decompile. (The latter is free, the former has a free for a limited time trial period.)
Alternatively, if you can get the full source code, you can simply remove all the content already out ther and publish it using the non-compiled method. Of course, there will be down time, and you'll need to test pretty carefully...
When you have a codebehind file, it needs to get compiled into a DLL, and that DLL needs to be in the bin directory of the webserver. It doesn't actually work fine without the Inherits - nothing from your codebehind would be in there - it may only display ok initially, but none of the events would fire.
If the rest of the site is all done with the code included in the .aspx pages, then those pages are all standalone. But if you want to use codebehinds, then you'll need to publish the DLL.
Test easiest way to get your code up and running would be publishing the code. Inside of your project in Visual Studio right click on your application and click on publish then for the location you can just create a folder on your local system and select only files needed to run this application then select publish. It will only copy the files needed to run the application and you can copy those files to your server and everything should be correct. I will also copy your web.config/app.config file so make sure that everything is correct in that file or delete that file from the directory once the publish is done.
So I eventually talked to the lead developer for the other group that works on the site. He explained that they do a Solution Rebuild then just move any changed as*x files and the /bin .dll. For some reason, my subversion client didn't actually update anything when I asked it to update, so my branch didn't have some new controls the other group made. When I would build my solution it didn't include the .dlls for the new controls, so when I uploaded my dll the new controls weren't defined and I got the same message. When I took the new dll down, my controls weren't defined.
Anyway, I fixed that. Thanks for the answers.

How to part Pre-compile a ASP.NET Website

I have a website with huge number of pages, i keep pre-compiled version (with fixed naming) on production server.
Every time i make any change on my code i have to Publish the whole website just for a small change.
It takes about an hour to get the website published before i can deploy my changes to production server.
Is there a way to publish only a batch of pages so that the Publish process is faster?
Is there any other option to save the publishing time?
NOTE: By publishing I mean pre-compiling
Any suggestions are welcome.
If you're modifying only the html tags (nto the server side tags) or css, you can deploy only the part you changed.
If it's compiled code you got no choice.
I think you might have to ask your self why it's taking an hour to publish your web site ? Is your compilation time that much long ? .
One method to reduce the compile time, and size of a web-site project is to split your website into several smaller and more maintainable sites.
You can still deploy these separate publishes together in production.
References to pages from other projects work perfectly. All your pages within the same application on IIS will share the same session. So to an end user, this will still appear to be one website.
Since you reduce the work to be done while publishing any given module publishes will be faster. Divide your modules as per what you see as a suitable batch.
You must be aware of this, but I will say it just for completion. When you publish a website you get the option,Use fixed naming and single page assemblies. Select this to have a different dll for each page in your bin directory. You only need to upload the pages and corresponding dlls where you made changes. If upload time is a concern, this will take care of it.
Microsoft doesn't really have an idea of "pre-compiling" if you notice your pages have 3 components to them, the *.designer, *.aspx *.cs. The *.cs all needs to be compiled into a *.dll to be deployed to your website. Traditionally there are two types of executables, exe's and dll's. Asp.Net websites are compiled into a dll for all the code behinds that run on the server. Microsoft does not have a way to "half" compile a dll and then merge it with the other half you haven't changed.
If your website is taking that long, to compile & deploy. I would suggest you have more of an architecture problem then a code problem. Where I work our main website is 3,000,000+ lines of code, to accomplish everything the user needs to do and does. We don't take an hour to deploy. however what we have done is broken our business logic up into a number of dll's over 100 dll's and our website project in and of it self is just the aspx and the bare bones code behind to drive the flow through to our business logic. This allows us to alter x number dll's with our changes to support a new feature, We don't have to deploy all 100 dll's every time just the ones that have changed, that's the nature of dll's. if our business logic was 100% contained in our website project, then our compile, deployment would be significantly longer.
You want to consider refactoring your code into dll's. Another option if you're not married to the ASPX/ASP.NET solution is to consider an ASP/MVC.NET solution. I would consider refactoring your site. If it takes that long there's some serious issues, even if you could break Data access into a separate dll, then you wouldn't have to constantly compile & deploy the dll which handles your data access, every time you changed the website, only when you changed the Data access layer as well.
As previous posts mention, you cannot do this in an automatic fashion, but you could manually deploy your files if you want to reduce your publishing time.
When publishing a website, all code files for your site are compiled into a single .dll file in the website bin folder and all .aspx files are be deployed to their relevant paths.
To update the site manually, simply build the website on your local machine to create an updated .dll and overwrite the .dll in the bin folder on the production server. If the source/HTML has been modified on any of your actual pages/.aspx files then you will also need to copy them over.
Steps:
Build website locally
Overwrite production server .dll with locally built .dll
Copy any .aspx pages to production server where HTML/Source modified
Very simple.
Have all the HTML content stored in separate files to the code. A database would be an excellent idea. All one would have to do to change some text or swap an image would be to go into the database or file for that content and change a few tags. I recommend MySQL.
:)

Is it possible to get app_offline to be ignored when running in visual studio?

I have a web app that has an app_offline.htm file, this file is stored in source control along with everything else.
The problem I have is that each time I (or any other developer) do a get latest on the source I get the app_offline.htm file and then when I try to run the app all I see is the app_offline rather than the actual web site.
Is there way that I can stop this from happening?
You can right click on the file and choose exclude from project. It renames the file so you IIS won't pick it up, but I'm pretty sure that Visual Studio will not remember that after you do a new checkout. (Can't verify this though)
Other than renaming it or removing it locally, it most certainly depends on your source control system. The whole point of source control is to "restore" a code source to a specific point. Checking out something other than the current state is kind of against the source controls principle..
Can you perhaps rename the file in source control and when you publish it you rename it to app_offline.htm then instead?

"Add as Link" for JavaScript files returning 404 in debug

Using a Visual Studio 2010 ASP.net web application, I have several projects that share some JavaScript/css files. The most logical way for them to share these files is to place the files in a single folder and each project has them included with the "Add as Link" option. However, if I add the files this way when I'm debugging using either the Visual Studio Development server or debugging using a local IIS web server all requests for these files return 404 Not Found errors. If I publish the site then the files are copied but that obviously doesn't help with debugging.
Is there something I'm missing or is this a failing on VS's part?
To overcome this problem some time ago I created a 'MSBuild.WebApplication.CopyContentLinkedFiles' nuget package. This package adds MsBuild target which copies all content files added as link to project folder during build.
Note: if you use source control then it is better to add copied files (from Web Application folder) to ignore list.
I wouldn't really call that a failing, since you asked for that behavior in the first place: linked items in Visual Studio projects are actual links to external files. Those files can reside anywhere on the disk and are not copied into the project folder.
You might want to copy those files locally yourself during a pre-build event. That way, the files will remain synchronized and you won't duplicate them until your first compile.
The problem seems to be that the website runs right from your source folders, rather than from the bin folder. This means that the file will be missing, whether or not it is copied to the output folder.
It's probable that running from a local or remote web server would not have this problem, though I didn't get that working, and I'd rather not add IIS to my local machine if I don't have to.
Adding a pre-build copy command did work. Note that the current directory will be the bin folder. (You can use cd to echo the current directory to the build window if you want to see it):
If the file is in another solution, your command will look something like (three ..s: one to get out of each of bin, project, and solution folders):
copy ..\..\..\OtherSolution\OtherProject\Scripts\MyJSFile.js ..\Scripts\
If it's in the same solution, but a different project:
copy ..\..\OtherProject\Scripts\MyJSFile.js ..\Scripts
One minor issue is that the link to the file will collide with the new copy of the file, even if you don't add it to your project. As long as you make the link first, it seems to work. If you copied the file first, you'll have to manually delete the copy, and then refresh the solution explorer before before being able to add the link.
Select the link in Solution Explorer and then look at properties window and set Copy To Output Directory to Copy Always. Linked items are set to Do Not Copy by default.
BTW, you can copy many files as links very easily directly from Solution Explorer when using VSCommands 2010 extension.
See this blog post about a simple addition to your project file.
http://mattperdeck.com/post/Copying-linked-content-files-at-each-build-using-MSBuild.aspx

Resources