Aspnet Compiler is compiling my aspx files - c#

I'm using the aspnet_compiler compiler program as part of the automated build procedure for a website. We have a website project and the build step generates the assembily for the project for the release build. However it generates these dlls in such a way that the aspx pages reference those at the moment randomly named assembilies. So my question is how would I modify this process to allow me to swap the dll's without updating the entire site. Also we're using nant at the moment for the build process.

Have you tried using the -u option? The reference is at http://msdn.microsoft.com/en-us/library/ms229863(VS.80).aspx.

The aspnet merge tool allows all the dlls to be merged into one explictly named assembily and updates the aspx and ascx files to reflect the appropriate assembily.

Related

Add C# code to exe file directly without using the build command from visual studio

I have an exe file for my application using visual c#.
Whenever I have to change, I go to visual studio, change or add the code and build the application.
So that my exe file will be updated.
Now what I want to do is I just want to add new changes c# script to exe directly.
I don't want to build the application from visual studio again and again whenever I have to change the code in application.
Because sometimes it's take too long to build for big application.
Is there any tools or way to do it?
Thanks.
Uhm no.
The most you can do is avoid visual studio, edit the source files using a lightweight editor, and re-compile the assembly using msbuild (e.g., msbuild.exe mysolution.sln).
If your project is large, building it can take some time. If you only need to change a small portion, you should seperate your project into smaller assemblies so your change in one assembly does not force a rebuild of your whole infrastructure.
If we're talking purely about building a project outside of visual studio then use an MSBuild scipt.
There is a decent tutorial here: http://goo.gl/MOseG
Note that you can reference static assemblies if you only want that project to be built, but be aware of stale references!
Now, let's have a look at the source of a your problem, large build that take a long time. I susggest you read here:
http://msdn.microsoft.com/en-us/library/ee817674.aspx
It may be wise to split you solution into several sub solutions.
Well you could seperate that file which you change often into an own assembly and just rebuild that assembly. Of course you need to make an reference to that assembly in your application.
Have you tried commandline compiling? It can be faster then Vs cause you dont have to open Vs (if you changed you code in notepad for example). Otherwise it nearly takes the same time (or longer cause you have to type in paths).
csc /out:YournewExe.exe YourFile.cs
Csc is the c# compiler and can be found at C:\Windows\Microsoft.NET\Framework\Version
Further information can be found here Click
Why don't you just save your project file everytime instead of building it? And when you finish working on it for today,just build the app then.
You don't have to test the app everytime through the .exe file,do you?

Add ascx.cs file to production web application

One of our clients has installed our web application into production.
We need to do a very quick patch to one of the aspx controls. I tried dropping the ascx and ascx.cs source files into the dir and unsurprisingly I got this error:
Exception type - HttpParseException - The base class includes the field 'foobar', but its type (UserControls_Controls_FOO) is not compatible with the type of control (ASP.usercontrols_controls_foo_ascx).
Yes, this approach is never a good idea, but is there anything I can do to the control to get it to run in the site instead of the version compiled into the DLL?
Doing a fresh install is not an option at this point.
no , you need to get it into compiled DLL and fresh deploy only then you can see the patch working
If you changed only ascx file you must update only it.
But if you updated ascx.cs you must Publish project and replace old bin directory with new one.
Also you can transform site to set of dynamically compiled pages, but it is hardcore old way and bad idea nowadays.

Post build events in Script#

I'm trying to create post build events to copy the final .js and .debug.js files for my script# projects into the proper directories. I can't use the regular output folder, since I have more than one project that references another project, and that always results in a build error (Unable to copy referenced script because it is being used by another process).
The problem is that the C# compiler appears to run the post build events BEFORE it writes the actual .js files, so they don't exist when the post build event happens.
Is there any other solution to make this work?
You can set up a DeploymentPath property in your csproj and the generated scripts will be copied there.
All of the logic is in here: https://github.com/nikhilk/scriptsharp/blob/cc/src/Core/Build/Tasks/ScriptCompilerTask.cs ... so another option is to customize the build task to exactly your requirements.
The latest work if you check out the github repo, also has the script# part of the build process done during the build step of an msbuild project, so that should free up the post-build step for you to do what you'd like with the generated scripts. See https://github.com/nikhilk/scriptsharp/blob/cc/src/Core/Build/ScriptSharp.targets. Again, its just msbuild stuff, so you could potentially customize the .targets file to your liking as well if it doesn't fit your needs.
I got around this by adding the "copy" command as a pre build step on the projects that were using the script# project output, then adding a dependency so that the script# project would be built first.

Is there a way to make user specific pre/post build events in Visual Studio projects?

I'm currently using a post build event in my project to copy my assemblies to another directory for debugging purposes. This is local to my machine, and is for debugging purposes only, so I would prefer to have it in a *.csproj.user file instead of a *.csproj file. I tried copying the responsible elements from the *.csproj to the *.csproj.user, but that didn't work.
Edit
To clarify, I do not want to put user specific commands in the post-build event in the *.csproj file. Instead, I want to put the post-build event commands in the *.csproj.user file. (From the answers so far, this is looking impossible)
To give more context, it is not a project reference. I am copying my assembly to the directory of the application that loads the assemblies at runtime. (Think plugins)
The short answer is no, not the way you want to do it :|
The slightly longer answer is sorta. You can in theory have specific build events triggered for individual users, but these would still be in the csproj file. You can run external events on builds and then allow these external events to run depending on what user is running them (as a script).
If this is for debug only I'd just insert them, do your build stuff and pull them out before uploading it to your version control system.
Use an if statement and an enviroment variable (in double quotes if required)
if "$(Username)" == "MyUser"
copy /y $(ProjectDir)memcached.$(ConfigurationName).config $(ProjectDir)memcached.config
You can utilize a custom build target that has a condition triggered by an environment variable. Then only set that variable on your machine.
Pre-/Post-build events are kept in the project file. VS provides no options.
You can introduce a custom (external) tool to perform such copying though and call it from menu, or macros and call it too.

Custom build step for C# project

In C++ projects there is the possibility to set a custom build step for files. Is there a similar functionality in C# projects? I couldn't really find anything.
One idea would be to create a second project (makefile or c++) and move the files there.
MsBuild should work for you although it might take some time to figure out how it works. It appears that you can setup a step that runs prior to building each .cs file by separating each .cs file into its own build group.
In MSBuild script for compiling each .cs file into an EXE, Dino Chiesa comments:
By using the %(CSFile.identity)
scalar, we run this task once for each
file. The converse would be
#(CSFile.identity). That would run
the compile once, for all files,
compiling them all together into a
single assembly.
Also, these links might help:
Custom build step for C# files
Master Complex Builds with MSBuild
No custom build step for individual files with C# projects. You could probably hack something together with MSBuild...
Look at the BeforeBuild and AfterBuild targets in your csproj file.
I think you are on the right track with your comment about multiple projects. Combine this with the fact that you can include multiple projects within a single Solution and you may have your answer. I use this functionality to build several components at a time and it works quite well.

Categories

Resources