新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论.NET,C#,ASP,VB技术
    [返回] 计算机科学论坛计算机技术与应用『 Dot NET,C#,ASP,VB 』 → C# Reference Assembly Custom Path 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5655 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: C# Reference Assembly Custom Path 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 Dot NET,C#,ASP,VB 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 C# Reference Assembly Custom Path


    C#.NET Assembly
    A C# assembly is basically any C# library. This means many C#.NET application commonly use reference assemblies in order to execute specialized parts of source code.

    For example, let's say you have a C#.NET application that processes images. This application uses all kinds of filters to modify images in different ways. Each filter's source code is in a C# library (dll) so it will be easier to update and maintain.

    Now the main C# application will reference the libraries (reference assemblies) for the needed source code when a user selects a certain filter.

    Using assemblies and libraries in C#.NET can be essential in creating a well structured application that is easy to maintain and expand.

    Default Reference Path
    The default path that a C#.Net application will look for a reference assembly, is directly in the same path. This means if you run the main C# program (let's say MainApp.exe) from the path C:\MyFolder\MainApp.exe. The program will expect all needed assemblies (our C# libraries) to be in the folder C:\MyFolder.

    Setting a Custom Reference Path
    Let's go back to our example image processing C# application. As the amount of filters increasing, having everything within one folder is both messy and unprofessional The solution is to place all common C# libraries, in this case all the filter dll's, in a subfolder of where the main C#.Net application is located.

    So let's say you want the main application in C:\MyFolder\MainApp.exe and the reference assemblies in C:\MyFolder\Filters.

    Here is how to tell the C# program to look for assemblies within its startup path and in a custom reference path. Go to where the Main void is (commonly in Program.cs). Add the following line before the main Form is initialized:

    AppDomain.CurrentDomain.AppendPrivatePath("Filters");Usually the line that would follow would be:

    Application.Run(new Form1());Notice that all you needed to add was the name of the subfolder and not the entire path. This is so you could move your C# application to a new folder and the C# code would still search for the same subfolders.

    Also notice that the function appends a private path. Meaning you can add as many subfolders as you wish as reference paths.


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/1/26 11:42:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Dot NET,C#,ASP,VB 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/2 23:42:02

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    1,078.125ms