How do you get the solution directory in C# (VS 2008) in code?

后端 未结 6 2355
时光取名叫无心
时光取名叫无心 2020-12-10 05:29

Got an annoying problem here. I\'ve got an NHibernate/Forms application I\'m working through SVN. I made some of my own controls, but when I drag and drop those (or view som

6条回答
  •  温柔的废话
    2020-12-10 06:02

    Update: Unfortunately, i don't know how of a way to get your solution folder at design time. So, technically, I am not answering your question, just offering a potential workaround.

    You can check if your control is in DesignMode and if it is, you can use Assembly.GetExecutingAssembly() to get the Assembly for your control and determine the location it was loaded from.

    Note that there are some caveats with the DesignTime property value, namely if your designing your control or if you are designing a Form that contains your control, it'll return properly true, but if you are designing a form that contains a control that contains your control, it'll retun false.

    You might want to skip the whole DesignTime check because of this and always look for the NHibernate config in the base path of your assembly, if your standard way to find that config file fails.

提交回复
热议问题