C# 制作独立文件或将输出文件放置在子文件夹中

问题描述 投票:0回答:1

我想将我的项目构建为独立的

.exe
或将其附带的所有文件放在子文件夹中。

构建信息:C#、.NET Framework 和 Visual Studio 2019 社区版。

当我构建项目时,它会输出这些文件:

Myapp.exe (of course)
Myapp.exe.config (I know this needs to be with the .exe)
Ookii.Dialogs.Wpf.dll
Ookii.Dialogs.Wpf.xml

我知道我可以用 fody Costura 构建它来集成

Ookii.Dialogs.Wpf.dll
并且可以工作,但它仍然有
.exe.config
Ookii.Dialogs.Wpf.xml

也许我不需要两者,配置文件中没有太多内容,但我需要

Ookii.Dialogs.Wpf.xml
吗?

如果是这样,是否可以将

Ookii.Dialogs.Wpf.xml
.exe.config
也添加到
.exe
中?

如果不可能在没有额外文件的情况下制作1个单独的

.exe
,我认为将所有文件放在一个子文件夹中会很方便,例如(
/Config
),除了
myapp.exe
之外。

那么它看起来像这样:

/Config   
  - Myapp.exe.config   
  - Ookii.Dialogs.Wpf.dll   
  - Ookii.Dialogs.Wpf.xml 
Myapp.exe

希望有人能帮我解决这个问题。

.exe.config
(删除了令牌和应用程序名称):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="myappnamehere" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=tokenhere" >           
            <section name="myapp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=tokenhere" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            <section name="myappnamehere.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=tokenhere" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
    <userSettings>
    </userSettings>
</configuration>

Ookii.Dialogs.Wpf.xml
代码中的一段 - 它非常大:

<?xml version="1.0"?>
<doc>
    <assembly>
        <name>Ookii.Dialogs.Wpf</name>
    </assembly>
    <members>
        <member name="T:Ookii.Dialogs.Wpf.TaskDialogItemCollection`1">
            <summary>
            Represents a list of <see cref="T:Ookii.Dialogs.Wpf.TaskDialogItem"/> objects.
            </summary>
            <typeparam name="T">The type of the task dialog item.</typeparam>
            <threadsafety instance="false" static="true"/>
        </member>
        <member name="M:Ookii.Dialogs.Wpf.TaskDialogItemCollection`1.ClearItems">
            <summary>
            Overrides the <see cref="M:System.Collections.ObjectModel.Collection`1.ClearItems"/> method.
            </summary>
        </member>
        <member name="M:Ookii.Dialogs.Wpf.TaskDialogItemCollection`1.InsertItem(System.Int32,`0)">
            <summary>
            Overrides the <see cref="M:System.Collections.ObjectModel.Collection`1.InsertItem(System.Int32,`0)"/> method.
            </summary>
            <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
            <param name="item">The object to insert. May not be <see langword="null"/>.</param>
            <exception cref="T:System.ArgumentNullException"><paramref name="item"/> is <see langword="null"/>.</exception>
            <exception cref="T:System.ArgumentException">The <see cref="T:Ookii.Dialogs.Wpf.TaskDialogItem"/> specified in <paramref name="item"/> is already associated with a different task dialog.</exception>
            <exception cref="T:System.InvalidOperationException">The <see cref="T:Ookii.Dialogs.Wpf.TaskDialogItem"/> specified in <paramref name="item"/> has a duplicate id or button type.</exception>
            <exception cref="T:System.ArgumentOutOfRangeException">
            <para>
              <paramref name="index"/> is less than zero.
            </para>
            <para>
              -or-
            </para>
            <para>
              <paramref name="index"/> is equal to or greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"/>.
            </para>
            </exception>
        </member>
        <member name="M:Ookii.Dialogs.Wpf.TaskDialogItemCollection`1.RemoveItem(System.Int32)">
            <summary>
            Overrides the <see cref="M:System.Collections.ObjectModel.Collection`1.RemoveItem(System.Int32)"/> method.
            </summary>
            <param name="index">The zero-based index of the element to remove.</param>
            <exception cref="T:System.ArgumentOutOfRangeException">
            <para>
              <paramref name="index"/> is less than zero.
            </para>
            <para>
              -or-
            </para>
            <para>
              <paramref name="index"/> is equal to or greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"/>.
            </para>
            </exception>
        </member>
        <member name="M:Ookii.Dialogs.Wpf.TaskDialogItemCollection`1.SetItem(System.Int32,`0)">
            <summary>
            Overrides the <see cref="M:System.Collections.ObjectModel.Collection`1.SetItem(System.Int32,`0)"/> method.
            </summary>
            <param name="index">The zero-based index of the element to replace.</param>
            <param name="item">The new value for the element at the specified index. May not be <see langword="null"/>.</param>
            <exception cref="T:System.ArgumentNullException"><paramref name="item"/> is <see langword="null"/>.</exception>
            <exception cref="T:System.ArgumentException">The <see cref="T:Ookii.Dialogs.Wpf.TaskDialogItem"/> specified in <paramref name="item"/> is already associated with a different task dialog.</exception>
            <exception cref="T:System.InvalidOperationException">The <see cref="T:Ookii.Dialogs.Wpf.TaskDialogItem"/> specified in <paramref name="item"/> has a duplicate id or button type.</exception>
            <exception cref="T:System.ArgumentOutOfRangeException">
            <para>
              <paramref name="index"/> is less than zero.
            </para>
            <para>
              -or-
            </para>
            <para>
              <paramref name="index"/> is equal to or greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"/>.
            </para>
            </exception>
        </member>
        <member name="T:Ookii.Dialogs.Wpf.Properties.Resources">
            <summary>
              A strongly-typed resource class, for looking up localized strings, etc.
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.ResourceManager">
            <summary>
              Returns the cached ResourceManager instance used by this class.
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.Culture">
            <summary>
              Overrides the current thread's CurrentUICulture property for all
              resource lookups using this strongly typed resource class.
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.AnimationLoadErrorFormat">
            <summary>
              Looks up a localized string similar to Unable to load the progress dialog animation: {0}.
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.CredentialEmptyTargetError">
            <summary>
              Looks up a localized string similar to The credential target may not be an empty string..
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.CredentialError">
            <summary>
              Looks up a localized string similar to An error occurred acquiring credentials..
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.CredentialPromptNotCalled">
            <summary>
              Looks up a localized string similar to PromptForCredentialsWithSave has not been called or the credentials were modified after the call..
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.DuplicateButtonTypeError">
            <summary>
              Looks up a localized string similar to The task dialog already has a non-custom button with the same type..
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.DuplicateItemIdError">
            <summary>
              Looks up a localized string similar to The task dialog already has an item with the same id..
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.FileNotFoundFormat">
            <summary>
              Looks up a localized string similar to The file &quot;{0}&quot; could not be found..
            </summary>
        </member>
        <member name="P:Ookii.Dialogs.Wpf.Properties.Resources.FolderBrowserDialogNoRootFolder">
            <summary>
              Looks up a localized string similar to Unable to retrieve the root folder..
            </summary>
        </member>

我已经做了什么:

Fody Costura 的 Ookii.Dialogs.Wpf.dll,它可以工作,但仍然得到其他文件。

要将 dll 放在子文件夹中,此代码也可以工作,但仅适用于 dll 文件...:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <probing privatePath="Config" />
    </assemblyBinding>
</runtime>
c# visual-studio-2019 exe .net-4.8
1个回答
0
投票

解决方案:

非常感谢@Serg和@marc_s,让我的问题更好地阅读代码和内容!

因此,如果您遇到与我相同的问题,那么如何解决它: 使用

Fody Costura
嵌入 dll,您可以删除
Ookii.Dialogs.Wpf.xml
。 对于
.exe.config
检查它是否用于我的情况,所以我可以删除它并在没有它的情况下工作,否则将配置文件留给你.exe。

也可以使用 Visual studio 2022 迁移到 .Net 8,但是在我的项目中我遇到了许多代码错误。

如果您想尝试一下,这里是操作方法。

© www.soinside.com 2019 - 2024. All rights reserved.