Add satellite assembly in a pre-compiled deployed website - asp.net

In order to make use of GetGlobalResourceObject() in Visual Studio 2008 I have to copy a .resx file into the folder App_GlobalResources of Visual Studio. After the application is precompiled, the resource files are being compiled into the corresponding satellite assemblies and deployed under the \bin\ folder by culture names. This all works fine.
However, I'm unable to add new satellite assemblies after the application has been precompiled. What I've done was:
Created a satellite assembly:
resgen resources.applicationresources.es-ES.resx resources.applicationresources.es-ES.resources
al /t:lib /culture:es-ES /embed:resources.applicationresources.es-ES.resources /out:App_GlobalResources.resources.dll
Created folder \bin\es-ES\ and deployed the .dll file there.
Unfortunately, the newly added satellite assembly is not being recognized by the GetGlobalResourceObject(), which falls back to the default (English) resource. There seems to be nothing wrong with the resource file because if I copy the same .resx file into App_GlobalResources and then compile the application, everything works just fine.
What am I missing? BTW my project type is website and not web application project.

(From Comment by #ksa)
One thing that can go wrong is an incorrect namespace path in the DLL produced by resgen, you can use ILDASM or Reflector to compare the namespaces in the working DLLs and the generated not working DLLS. You can then change your resgen command line to generate with the correct namespace.

Try hooking up to the AssemblyResolve event in AppDomain.CurrentDomain and see if it's actualy looking for the assembly. If it does look for it, all you need to do is keep a list of dynamically loaded assemblies and their paths.
One note about AssemblyResolve, if you don't have the assembly, return null. That's the default behavior.

Related

publish asp.net website into single dll file

I got a asp.net website from my client that need to be modified. The problem is that the old company was uploading the project as a release which means no code but a sinlge dll file.
We can make a single dll file the project type is web application not a website!!
Can you adivse how to publish sinlgle dll fiel.
Regards,
Moayyad
If you want a single DLL, then convert your website into a web application. Once you convert, everything inside your project will be compiled into a single DLL file.But still, any external assemblies will be inside their own DLL files.

Precompiling a single file using Aspnet_compiler (or another way)

Is there a way to precompile only a file of choice in a web site (using fixed names), instead of the whole site? e.g. : If I have a user control MyUserControl.ascx, only precompile this file?
Yes, you can compile .ascx files. They can be complied into dll files and can be referenced into your project.
for that you need to put the ascx and its cs file in a new web project, and complile it into a dll using Microsoft Web Deployment Tool (if I remember correctly).

Where are Web Application Project Assembly references stored?

Where are assembly refernces stored for a web application?
In a Web Site, I see assembly tags written to the assembly node in the web.config when you add a reference. I am just curious as to how the Web Application Project makes the connection to get the correct local dll?
I manually add the reference and the application builds, but the dll is not imported into the BIN folder, and the assembly nodes are not created in the web config as they are in a Web Site. I do a solution search for the text 'assembly="SomeAssembly..." and no results are found.
I am just curious as I am trying to centralize updating assembly references as a 3rd party control vendor puts out hotfixes on a regular basis and we end up having to run around and update all the individual page refernces to the assembly. I was able to do this effectively in the Web Site project, but I am fairly new to Web Application Projects. Any advice or links would be appreciated. I guess I'm looking for tips on assembly & control reference management for ASP.NET Web Application Projects.
Like most Visual Studio projects, references are kept in the project.
There are two kinds of reference:
Project References are references to another project in the same solution. They look like this:
<ProjectReference Include="..\VBClassLibrary1\VBClassLibrary1.vbproj">
<Project>{045D7D9F-8E44-4C4B-95F8-620E86593C5B}</Project>
<Name>VBClassLibrary1</Name>
</ProjectReference>
File references are references to an arbitrary file on disk:
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
If you expand the References folder and click on a reference, then look in the Properties window, you'll see that both kinds of reference have a "Copy Local" property. For project references it defaults to true, for file references to false (though maybe that's only if the file is in the GAC). Changing the default adds:
<Private>False</Private>
Since the assembly was not imported to the BIN folder, and your application works, I assume that it is stored in the GAC (global assembly cache) and marked as "copy local=false" in the reference properties. You don't see the reference to the assembly in the web.config, since your code behind assembly - YourApp.dll (which is always created for web-applications), contains a standard assembly reference to that assembly. When you run your application it loads the assembly from the GAC.
Those "missing" dlls are probably in the Global Assembly Cache and are available to all .NET applications.
You can add control references to the pages/controls section of web.config, which will apply to all pages in the application.
I had the same issue, deleting .vs folder in the directory of the project solved the issue for me as it forced the recreation of .suo file which (though bite code) had reference to the web.config file in the wrong directory

Why does ASP.NET web site reference assembly from GAC, when adding local reference?

When you use ASP.NET web site (instead of web application model) and add reference to an assembly from local folder, Visual Studio, it seems, understands that this local assembly is also in GAC and so does NOT copy this assembly to bin folder (as it does with non-GAC assemblies), but simply adds new record in web.config file.
Why such a behaviour? Is it possible to force copy to bin folder (I need this since .dll is not on target environment)? I can add assembly to bin folder as file and it will work, but in this case bin folder contents will be in source control, which is not good.
You can set the Copy Local property to True on the reference. That should add it to the bin folder - on a Web Application project.
But for a Web Site project, when you add a reference, all it does is add a line to the web.config that references the assembly. It will look for this file first in the bin folder, and then in the GAC if it is not found.
You have two options: require the assembly to be installed in the GAC on the target machine (in which case, XCOPY deployment is not possible) or include all required assemblies in the bin folder, either by copying them in or writing a post-build script that does so. You can find the .dll by using the command prompt and going to c:\windows\assembly\GAC, find the assembly you are interested in, cd into that directory and then cd into the directory with the version you are interested in. This will give you the path to use in your post-build script. For example, for the Accessibility assembly in the GAC, you'd end up with this path:
c:\Windows\assembly\GAC\Accessibility\1.0.5000.0__b03f5f7f11d50a3a\Accessibility.dll
You say including the bin folder contents in source control is not good. This is generally regarded as true for binaries you build, but in your case, you have binary assets that are not compiled as part of your project. Philosophically, these are equivalent to images: binary assets not compiled as part of your project. I would argue they belong in source control as much as any other binary your project relies on. But it is a personal choice.
If you are using a website project in Visual Studio and a reference keeps pointing it to the GAC version instead of some other folder (eg lib), you will need to create a xxxx.dll.refresh file in your /bin folder, where xxxx is the offending dll you are referencing.
This will resolve build problems with MSBuild too where the server will expect the dll to be in the GAC. The .refresh file will get the file from the correct relative path to do builds correctly.
At run time, assemblies must be in one of two locations: the output path of the project or the global assembly cache (see Working with Assemblies and the Global Assembly Cache). If the project contains a reference to an object that is not in one of these locations, then when the project is built, the reference must be copied to the output path of the project. The CopyLocal property indicates whether this copy needs to be made. If the value is true, the reference is copied. If false, the reference is not copied.
The project-assigned value of CopyLocal is determined in the following order:
If the reference is another project, called a project-to-project reference, then the value is true.
If the assembly is found in the global assembly cache, the value is false.
As a special case, the value for the mscorlib.dll reference is false.
If the assembly is found in the Framework SDK folder, then the value is false.
Otherwise, the value is true.
Hope this helps
s
For information on how to set the Copy Local Property of a Reference for a web project (not a web application), see:
http://msdn.microsoft.com/en-us/library/t1zz5y8c(v=VS.100).aspx

VS2008 Web Deployment Project Section Replacement with Elmah

I'm using a web deployment project and want to do some section replacement with the emlah/errorMail section. I don't want to send emails in debug build mode.
I have created the custom section and put it in an errorMail.config. In the properties of web deploy project under replacements, I have elmah/errorMail=errorMail.config.
The error I'm getting is An error occurred creating the configuration section handler for elmah/errorMail: Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.
I'm guessing this is happening because Elmah is not in the GAC or it's not one of my projects. The Elmah.dll file does copy to the output\bin folder just fine though.
Is there a way to have section replacements work with 3rd party dlls?
[EDIT]
I found that if I drop the dll in question into the project folder for the web deployment project, that it will work fine. This is less than optimal.
So now my question is, how can I get this to work without having to put the dll in the GAC or having to copy the dll into the web deployment project folder?
If you add a reference to the elmah dll from your webproject, then it will automatically copy the dll to the output folder when you build it.
Those are the only 2 options though: to have the dll copied to the output directory or to put it in the GAC
A technique proposed here dynamically loads an assembly during the web deployment build process so that it doesn't have to be in the GAC. I tried, but was unable to get it to work, though.

Resources