VSTO 2010文档级自定义 - 无法在C:\ program Files \中找到app.config文件 [英] VSTO 2010 Document-level customization - Unable to find app.config file in C:\program files\
问题描述
我已经使用安装项目部署了Excel 2010文档级自定义。 自定义在我的机器上成功安装(Windows 7 64位)但是当我在客户端机器上部署时,应用程序无法找到
app.config文件。 目标计算机是Windows XP 32位。 具有讽刺意味的是,在安装之后,如果我将安装移动到除c:\program files \ makeufacturer \之外的文件夹,则应用程序可以正常运行。
I have an Excel 2010 document-level customization that I have deployed with a setup project. The customization installs successfully on my machine (Windows 7 64 bit) but when I deploy it on client machine, the application is unable to find the app.config file. The target machine is Windows XP 32-bit. Ironically, after the install, if I move the install to a folder besides c:\program files\manufacturer\ the application works successfully.
我看过参考文献到VSTo 4.0 SP1( http://msdnrss.thecoderblogs.com/2011/06/vsto-4-0-sp1-will-cause-a-vsto-addin-to-not-find-its-config-file /)
这适用于应用程序级别的插件,我的是文档级自定义。
I've seen the references to VSTo 4.0 SP1 (http://msdnrss.thecoderblogs.com/2011/06/vsto-4-0-sp1-will-cause-a-vsto-addin-to-not-find-its-config-file/) this applies to application-level addins and mine is a document-level customization.
推荐答案
嗨AddOnsInc,
Hi AddOnsInc,
感谢您在MSDN论坛上发帖。
Thanks for posting in the MSDN Forum.
我建议您尝试以下方案,看看它是否可以帮到您:
I would recommend you try following scenario to see whether it can help you out:
app.config
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MyValue" type="System.Configuration.SingleTagSectionHandler"/>
</configSections>
<MyValue value="Hellow World" />
</configuration>
ThisWorkbook.cs
ThisWorkbook.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Microsoft.Office.Tools.Excel;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using log4net;
using MyLog4Net;
using System.Configuration;
using System.Collections;
namespace ExcelWorkbook21
{
public partial class ThisWorkbook
{
/*
* Please omit ILog variable, I just use it to track my program.
*/
private ILog Log = MyLog4Net.MyLog4Net.Generator1(
AppDomain.CurrentDomain.BaseDirectory
+ ".log", typeof(ThisWorkbook), "DEBUG",true);
private void ThisWorkbook_Startup(object sender, System.EventArgs e)
{
try
{
MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory
+ "logReport.log");
Configuration cf = ConfigurationManager.OpenExeConfiguration(
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
.Replace(".config", ""));
Log.Info("Get the configuration");
Hashtable ht = (Hashtable)ConfigurationManager
.GetSection("MyValue");
Log.Info("Get the Configuration's Hash Map");
MessageBox.Show(ht["value"].ToString());
Log.Info("Show value");
}
catch (Exception ex)
{
Log.Error(string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
}
}
private void ThisWorkbook_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisWorkbook_Startup);
this.Shutdown += new System.EventHandler(ThisWorkbook_Shutdown);
}
#endregion
}
}
祝你有个美好的一天,
Tom
这篇关于VSTO 2010文档级自定义 - 无法在C:\ program Files \中找到app.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!