【问题标题】:Why need projectname.exe.config to run exe file in vb.net为什么需要 projectname.exe.config 在 vb.net 中运行 exe 文件
【发布时间】:2018-05-26 15:50:18
【问题描述】:

我使用 Visual Studio 2010 和 MS SQL Server 2014 开发了一个 vb.net 应用程序。我使用水晶报表来进行报告。

目标框架 4.0

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>

使用水晶报表作为 构建操作 = 嵌入式资源 复制到输出目录 = 不要复制

在代码中水晶报表被访问为

Dim cryRpt As New myReportName cryRpt.SetDataSource(xdataset.Tables(0))

问题是当我运行位于 myProject\bin\Debug 中的 myproject.exe 时,它​​对于表单和水晶报表都可以正常工作。

但是如果将 myproject.exe 复制到任何其他位置,它会在运行时崩溃,其中数据集被分配给报告。 现在,如果我将 myproject.exe.config 文件复制到与 exe 文件相同的位置,它将成功运行。

那么为什么 exe 文件需要 myproject.exe.config 才能运行,如果它使用数据集进行记录。 我还需要使用我的 exe 文件部署 myproject.exe.config 吗?

问候。

这是我的配置文件中的代码

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
    <sources>
        <!-- This section defines the logging configuration for My.Application.Log -->
        <source name="DefaultSource" switchName="DefaultSwitch">
            <listeners>
                <add name="FileLog"/>
                <!-- Uncomment the below section to write to the Application Event Log -->
                <!--<add name="EventLog"/>-->
            </listeners>
        </source>
    </sources>
    <switches>
        <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
        <add name="FileLog"
             type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" 
             initializeData="FileLogWriter"/>
        <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
        <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
    </sharedListeners>
</system.diagnostics>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

【问题讨论】:

  • 有些东西依赖于配置,就是这样。
  • 运行 EXE 不需要配置文件。但是,如果您的应用程序中的某些代码依赖于存储在配置文件中的配置数据,那么如果该配置文件不存在,显然这将是一个问题。在您的情况下,很可能是您的配置文件包含数据库连接字符串。
  • 如果您要发布应用程序,您可以查看属性 > 发布 > 应用程序文件并将配置文件设置为必需的包含文件,它将包含在分发中。
  • 配置代码已添加,请查看

标签: vb.net crystal-reports


【解决方案1】:

My.Settings 使用我认为的 .exe.config 文件。最简单的方法是打开它,看看里面存储了哪些设置。然后,您可以更改代码以将这些设置存储在其他位置。

【讨论】:

  • 这是一个 vb.net winforms 应用程序
猜你喜欢
  • 1970-01-01
  • 2012-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-15
  • 1970-01-01
  • 2013-01-05
相关资源
最近更新 更多