开发者

How can I find out the name of my VS2010 solution / Application from inside my C# program

I know this is a strange request but I have code开发者_开发百科 that is shared between different solutions. When I run the code I would like it to act "slightly" different.

Is there a way that I could check what bin/application/solution is being executed?

Hope someone has some good ideas.

Thanks,

Mandy Wilson (FPL West Palm Beach)


You can call Assembly.GetEntryAssembly() to find the Assembly instance that the user launched.
You can then check its AssemblyName or Location.


Not sure about your actual question on solution name, but can't you just put a different marker in the Config file for each solution, and have the logic switch based on that? Say:

<appSettings>
  <add key="AppType" value="SomeType1" />
</appSettings>

Then read that setting in your shared code and have it behave different based on the actual value of that key.


I would recommend to use settings and configure the behavior explicitly on deployment.

Keywords are App Config and the System.Configuration namespace.

Application Settings:

<appSettings>
     <add key="AppType" value="SomeType" />
</appSettings>

Get the value:

var appType = System.Configuration.ConfigurationManager.AppSettings["AppType"]


Using meta information from the executing program is, I think, not the best approach. Generally, I'd approach this one of two ways. First, using configuration files. Store the information that's different for each solution in a configuration file and use the configuration file settings to drive program behavior. If you're unwilling to allow the user to change program behavior through the configuration file, then I'd use a plugin architecture and provide the configuration via the plugin. Your common code would depend on the plugin interface and in each solution you'd simply construct a different version of the plugin that contains the appropriate configuration information.


If I understand what your trying to you check the ProductName of each application.

if (Application.ProductName == "App1")
{
    // Action
}
else if (Application.ProductName == "App2")
{
    // Other Actions
}

I hope i understood what you'r trying to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜