Modify the version information of a built .NET assembly - assemblies

Is there a better way to modify the version information of a .NET assembly of the one I am currently using.
My current approach is the following.
I do disassemble the assembly with ildasm:
ildasm /nobar Riolo.WebUI.dll /out=Riolo.WebUI.il
This will generated also a Riolo.WebUI.res compiled resource file, that I then open and modify with the user interface of Visual Studio, then I do reassemble the assembly back with ilasm:
ilasm Riolo.WebUI.il /OUTPUT=Riolo.WebUI.dll /RESOURCE=Riolo.WebUI.res /DLL /PDB
There are various issues with this process, the main is obviously that I feel like shooting at a mosquito with a broadside of carronades, then that as I don't know how decompile .res files to .rc files with the command line, I cannot use a command line script, as I have to open Visual Studio to modify the .res file, which means it is very time consuming and somewhat error prone, and, last but not least, I do feel that roundtripping assemblies I may well end up loosing information, even if unwittingly, hence I am afraid I will early or later be bitten in some yet unforeseen scenario.

Related

Determine Version of .NET Software Running

This may be a stupid question and/or a futile effort -- you've been warned...
I have a ASP .NET application (with the VB parts compiled to a DLL). This application has been around a while and the person who wrote it apparently messed up the old source code repository system. He is no longer around and I'm not clear on whether the source code I was given was a re-write or an older version (or by some strange luck the actual version of the website running).
Being that part of this website is running as a DLL, what is the best way I can go about in determining if the version of the source code I have matches what is running? I'm unable to setup an IIS server to throw this on (licensing/server cost/time/etc).
Is there a better way than compiling the project and then finding some disassembler and doing a comparison?
Is there a better way than compiling the project and then finding some disassembler and doing a comparison?
That's what I've done in the past in your situation.
Open each compiled assembly using ILSpy, and use the option "File / Save Code" to generate source files.
Build the source code from your source code repository, and use ILSpy to generate source files.
Compare the results of 1 and 2.
Obviously this won't give you the whole picture - you'll also need to compare aspx files, config files, ..., but it's the only approach I know.

VS 2005, website project: managed C++ assemblies require dependencies in path, not bin dir?

I'm trying to build a VS 2005 website project which depends on several managed C++ assemblies. One of the managed C++ assemblies depends (static-load) on an unmanaged DLL which uses __declspec(dllexport) to export classes.
For some reason, I get the following build error:
Error 4 The specified module could not be found. (Exception from HRESULT: 0x8007007E)
(From build output details):
(0): Build (web): The specified module could not be found. (Exception from HRESULT: 0x8007007E)
when I build with the unmanaged DLL in the website's \Bin\ directory, but not in the path. If I put the unmanaged DLL in the path, then re-start visual studio, it builds and runs just fine.
Note: This thread seemed related, but I haven't gotten as far as deployment yet: Unmanaged DLLs fail to load on ASP.NET server
Is there any way to get this .sln building correctly with unmanaged DLL's in \Bin\ rather than the path? (I'd really prefer to keep these as part of the website, not the system)
Edit:
It seems I've misunderstood the purpose of the \Bin\ folder to some degree. Sounds like nothing except managed assemblies should go there. (So COM objects and other unmanaged DLLs they rely on which I've been placing there probably belong someplace else.)
I believe that ASP.NET copies your assemblies around quite a bit, to avoid locking the original DLL (which would prevent overwriting with a newer version). Then when you do overwrite it, it needs a copy of the old version until all outstanding requests complete, alongside the new version being used for new requests.
In summary, your DLL doesn't run from the \bin\ directory where you put it, and it looks for native dependencies where it actually does run.
Your options are to put the native DLLs in the path, or else add code to explicitly copy them to the "real" assembly directory as needed. But your code shouldn't even have permission to write to the filesystem, so I think you're stuck using the path.
Do note, though, that you can add directories to the application's own environment, without affecting the global path. For example, p/invoke SetDllDirectory Don't add \bin\ though. Put your native DLLs in a separate directory like \bin\native or \bin\x86, so when you change the search path you don't change which managed DLLs are found.
Edit:
This only works if the managed DLL delay loads any unmanaged native DLLs it links against (using /DELAYLOAD). Otherwise compilation of global.asax (or wherever the path setting happens) will fail.

Is it possible to (re)create a PDB file after a DLL is made

I have the DLL and I have the exact sources used to create the DLL. I want our local symbol server to work when we get a dump file from customers. (Updating the DLL at the customer site can't be done before the next patch/release of our product)
That seems to be not possible. Have a look at this here: Why does Visual Studio require debugger symbol files to exactly match the binary files that they were built with?
Or this article: PDB Files: What Every Developer Must Know
Quote out of "PDB Files: What Every...":
The extremely important part is how the debugger knows this is the
exact matching PDB file for this binary. That's done through a GUID
that's embedded in both the PDB file and the binary. If the GUID does
not match, you certainly won't debug the module at the source code
level.
The .NET compiler, and for native the linker, puts this GUID into the
binary and PDB. Since the act of compiling creates this GUID, stop and
think about this for a moment. If you have yesterday's build and did
not save the PDB file will you ever be able to debug the binary again?
No! This is why it is so critical to save your PDB files for every
build. Because I know you're thinking it, I'll go ahead and answer the
question already forming in your mind: no, there's no way to change
the GUID.

Automating finding compile errors in ASP.NET pages

I have an ASP.NET website where the pages call a few components in DLLs. I need to change the signature of a method in the component, and short of doing a text search, don't know if this will break any pages or not. IMO, this is the weakness of web programming -- you don't get the benefit of a compiler telling you about syntax errors.
But it doesn't need to be so. Does anyone know if there is a way to run a spider over a website watching for compile errors, or perhaps some tool that would compile all the .aspx files in a folder structure looking for compile errors?
This is merely for syntax checking -- not to actually pre-compile the website.
EDIT It looks like aspnet_compiler is being recommended. I don't use Visual Studio projects for the website -- it's grown over time with my own templating system (back before Master Pages were available). So something that would run aspnet_compiler over all the files in a folder might work...
There is a flag that you can put on your project that tells it to compile all the aspx files when the project is compiled. It adds time to your build, but it can sometimes be worthwhile. See http://mikehadlow.blogspot.com/2008/05/compiling-aspx-templates-using.html
Also, Resharper is really good at finding references to methods, even in aspx files. So if you use Resharper to rename a method, as long as your solution includes the web project, it'll find and rename that method in the aspx files, too.
This is one of the many reasons we use development tools like Visual Studio in the first place. The single easiest way to do what you're asking is to develop with an IDE that DOES compile and check for errors, even ifyou choose to publish teh un-compiled code.
Since Microsoft offers Visual Web Developer for free, there's really no reason to NOT use it.
The compiler will automatically catch and any report any errors in your .cs source or code-behind pages. Your assumption that the compiler won't catch syntax errors (such as getting the arguments in the wrong order when calling a method, etc) is incorrect - that's one of the primary benefits of using a compiled language. If you're experiencing something that contradicts this, please post some code.
If you're concerned about errors in the ASPX files or in your views (if using MVC), you can have the IDE precompile ASPX files, as well.
See this article for more information.
I turn this off most of the time since it slows down compilation, but I use it before deploying a site as an extra verification step.

ASP.NET: The file name generation rule for pre-compiled files

After pre-compiled a ASP.NET web site, I got many files with the names like
App_Web_accountbalance.aspx.dfa151d5.dll
Do you know the rule for the random chars (in bold) above?
Can we fix the random chars?
The reason to fix it is that if we modify AccountBalance.aspx file later and re-compile the web site, can we just replace App_Web_accountbalance.aspx.dfa151d5.dll.
Thank you.
The characters are not random, but more in line with hashing. The purpose is to make the file name unique in the bin folder. Although not advisable, you can replace just certain files to update your website. If you modify AccountBalance.aspx and recompile, you need to replace App_Web_accountbalance.aspx.dfa151d5.dll, accountbalance.aspx.dfa151d5.compiled, and other assemblies and files that your aspx file depends.
I derived the answer from my experience. I was not looking for the file naming rule, but a way to deploy just the assembly of a changed page, same reason as the original post.
The setup:
A web application, deployed non-updateable (updatable=”false” in PrecompileApp.config), pre-compiled assemblies with no fixed names
What I did:
Make the change to the page (say, a.aspx) in development (Visual Studio 2010)
Publish the site with fixed naming to local drive (Build > Publish Web Site, check the box: Use fixed naming and single page assemblies)
Go to the bin folder of the local publish site and look for a.aspx.xxx.compiled
Open the file with Notepad and note any dependency (say, b.aspx, c.master)
Copy all the affected assemblies and the .compiled files to the bin folder in production server. In this example, they are:
a.aspx.xxx.compiled
b.aspx.xxx.compiled
c.master.xxx.compiled
App_Web_a.aspx.xxx.dll
App_Web_b.aspx.xxx.dll
App_Web_c.master.xxx.dll
If you want to know my story, the change was due to a change in a factor in a calculation. The customer knew of the change much earlier, but did not let us know until it became urgent. A proper deployment would involve other parties and much coordination, and would be too late. Plus, I only had the source code of two versions back, and requesting the latest would take time. So, a hot fix on just that calculation change was required as a temporary measure.
1) you can generate single assembly per web application if you want. So when you make a change in web application, you only need to deploy just one dll.
for this, you can check option "Use fixed naming and single page assemblies"
2) Reference from MSDN Article: "The assembly names are generated automatically by the compiler and it is therefore not obvious which assemblies map to which source files. The compiler also creates new names each time it runs, so that the names of assemblies might not be the same after each compilation. In addition, if source files have changed, the compiler might batch up source files differently, meaning that the resulting assemblies do not necessarily represent the same source files. If you are maintaining a deployed Web site and want to update only the assemblies for recent changes, the output from batch compilation can make that job more complicated.
To help you in this situation, aspnet_compiler.exe supports an option specifically designed for packaging and release management: the -fixednames option. This option enables you to create compiler output that has two benefits. The first is that the assemblies produced by the compiler have the same names each time you compile. The second is that the assemblies are based on the same input files each time."
http://msdn.microsoft.com/en-us/library/aa479044.aspx

Resources