0

Is there a way to configure the Build Action for an NHibernate mapping .hbm.xml file from within the NHibernate mapping .hbm.xml file itself or at the very least another configuration xml file?

As much as I appreciate many of Microsoft Visual Studio 2010's features, I don't like setting the "Embedded Resource" as Build Action for this hbm.xml file manually by doing the following:

  1. (Dislike manual approach)(Microsoft Support Docs) Right-click either the file that is of interest, then select Properties.
  2. (Dislike manual approach)(Microsoft Support Docs)In the Properties dialog box, locate the Build Action property. By default, this property is set to Content. Click the property and change the Build Action property to Embedded Resource.

Also, I don't like doing it programmaticly in the the CSharp code. Is there a way to configure the Build Action for an NHibernate mapping .hbm.xml file from within the NHibernate mapping .hbm.xml file itself or at the very least another configuration xml file? Could someone please suggest how I could do it using xml?

Spontifixus
  • 6,570
  • 9
  • 45
  • 63
crazyTech
  • 1,379
  • 3
  • 32
  • 67
  • 1
    Why do you dislike using embedded resources? Why is this an issue. If you are that against it then your only other option is to use Fluent or the new mapping-by-code syntax and drop xml completey – Rippo Jan 28 '13 at 18:19
  • @Rippo I like using "embedded resources".However, I want to configure the buildAction from within an XML file. I don't like configuring buildAction manually in Visual Studio. Is there a way to configure buildAction to "embedded resources" using xml? – crazyTech Jan 28 '13 at 18:29
  • 1
    Your `.csproj` file (where the build action is) *is* an XML file. Just edit it, do search and replace, use a macro, whatever. – Diego Mijelshon Jan 28 '13 at 18:34
  • @user1338998 I would like to set "Build Action" to "Embedded resources" for xml with out manually.If you solved this please suggest me with your sharing code. – Rajkumar Reddy Feb 06 '13 at 12:11
  • @rajkumar-reddy I saw xml tags for "Embedded Resources" used in the .csproj file. The aforementioned xml tags would specify files that are embedded resources. However, I don't feel that writing programs or scripts to change the .csproj file is ideal because it is such a critical system file that Visual Studio uses to open up a project. Maybe you and I should start using the mapping-by-code syntax in NHibernate so that we can move away from XML. – crazyTech Feb 07 '13 at 01:19

1 Answers1

1

I solved this with out changing xml file properties to Embedded Resource.I enforced those dynamically generated .hbm.xml to NHibernate by using following code.Then I can able to bind this mapping files dynamically.

 Configuration cfg = new Configuration();
 cfg.Configure();
 string   file="@\\mappingfilesPath \\DynamicMappingfiles.hbm.xml";
 cfg.AddFile(new FileInfo(file));
 cfg.AddAssembly(this.GetType().Assembly);
Srinivas Adari
  • 105
  • 1
  • 2
  • 13
  • Thanks @srinivasadari. My Manager told us to switch to Microsoft Entity Framework so I'm leaving NHibernate. – crazyTech Apr 16 '13 at 13:45