Я хочу создать свой проект как отдельный .exe или поместить все прилагаемые к нему файлы в подпапку.
Информация о сборке: C#, .NET Framework с версией Visual Studio 2019 Community.
Когда я создаю свой проект, он выводит эти файлы:
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 "{0}" 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>
Коротко о том, что я уже сделал:
Фоди Костура для Ookii.Dialogs.Wpf.dll, он работает, но другие файлы все еще есть.
Чтобы поместить dll в подпапку, этот код также работает, но только для файлов dll...:
<runtime>
<assemblyBinding xmlns = "urn:schemas-microsoft-com:asm.v1">
<probing privatePath = "Config" />
</assemblyBinding>
</runtime>
Хорошо, спасибо, а .exe.config мне нужно сохранить и с этим небольшим количеством кода? И действительно, возможно, если у меня будет время в будущем, я перейду на Net 8.
Насчет .exe.config - это зависит. Он может содержать переключатели времени выполнения и другие параметры, которые будут влиять на поведение вашего кода. Но если он не содержит никаких настроек (как в вашем образце), думаю, его можно удалить.
Окей, да, это полный .exe.config. Хорошо, сейчас я буду использовать Fody Costura для встраивания dll и удаления всех остальных файлов. Огромное спасибо за помощь! Ой, кстати, я уже пытался перейти на .Net8, просто чтобы посмотреть, как он работает, но у меня было много ошибок в коде, поэтому я сейчас обновлю это приложение до .Net framework 4.8 и, возможно, в будущем я снова посмотрю на него. .Net8. В любом случае еще раз спасибо за помощь.





Решение:
Большое спасибо и низкий поклон @Сергу и @ marc_s за то, что сделали мой Вопрос более читабельным с помощью кодов и прочего!
Итак, если у вас возник тот же вопрос, что и у меня, вот как его исправить:
Используйте Fody Costura, чтобы встроить библиотеки DLL, и вы можете удалить Ookii.Dialogs.Wpf.xml.
Чтобы .exe.config проверить, использовалось ли оно для чего-то в моем случае, это не так, чтобы я мог удалить его и работать без него, иначе оставьте файл конфигурации с собой .exe.
Также возможно перейти на .Net 8 с помощью Visual Studio 2022, однако в моем проекте возникло множество ошибок кода.
1.
xmlвам не нужен, его можно смело удалить. 2. Возможно, вы захотите перейти с net framework на net8, а затем использовать однофайловую публикацию (Learn.microsoft.com/en-us/dotnet/core/deploying/single-file/…)