如何将 app.config 与 Visual Studio 加载项一起使用?

发布于 2024-07-09 05:50:03 字数 79 浏览 9 评论 0原文

我正在构建一个简单的 VS2008 插件。 存储自定义运行时设置的最佳实践是什么? app.config 存储在哪里以及如何从加载项访问它?

I'm building a simple VS2008 add-in. What is the best practice for storing custom run-time settings? Where do you store the app.config and how do you access it from the add-in?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丿*梦醉红颜 2024-07-16 05:50:03

尝试使用 System.IO.IsolatedStorageFile (尚未测试示例代码..只是为了展示想法)

写作

using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly())
    {
       using (StreamWriter stream = new StreamWriter(new IsolatedStorageFileStream("YourConfig.xml", FileMode.Create, file)))
       {
          stream.Write(YourXmlDocOfConfiguration);
       }
       stream.Flush();
       stream.Close();
     }

阅读

 string yourConfigXmlString;
    using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly())
    {
       string[] files = file.GetFileNames("YourConfig.Xml");
       if (files.Length > 0 && files[0] == "YourConfig.xml"))
       {
          using (StreamReader stream = new StreamReader(new IsolatedStorageFileStream("YourConfig.xml", FileMode.Open, file)))
          { 
            yourConfigXmlString = stream.ReadToEnd();
          }             
       }
     }

Try something like this with System.IO.IsolatedStorageFile (haven't tested sample code.. it's just to show the idea)

Writing

using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly())
    {
       using (StreamWriter stream = new StreamWriter(new IsolatedStorageFileStream("YourConfig.xml", FileMode.Create, file)))
       {
          stream.Write(YourXmlDocOfConfiguration);
       }
       stream.Flush();
       stream.Close();
     }

Reading

 string yourConfigXmlString;
    using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly())
    {
       string[] files = file.GetFileNames("YourConfig.Xml");
       if (files.Length > 0 && files[0] == "YourConfig.xml"))
       {
          using (StreamReader stream = new StreamReader(new IsolatedStorageFileStream("YourConfig.xml", FileMode.Open, file)))
          { 
            yourConfigXmlString = stream.ReadToEnd();
          }             
       }
     }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文