【问题标题】:How to i create a custom build directory for my WPA app如何为我的 WPA 应用程序创建自定义构建目录
【发布时间】:2020-06-30 13:37:06
【问题描述】:

我想清理我的应用程序生成的构建,以便应用程序的文件夹包含特定的文件夹层次结构,其中所有各种自动包含的 .dll 都放置在二级文件夹中,而不是在我的 .exe 旁边

我将如何在 C# VS2019 解决方案中执行此操作?

所需的示例结构:

[App]
  [Resources]
    Newtonsoft.Json.dll
    System.Data.SQLite.dll
    etc...
  [Data]
    Data.sqlite3
    etc...
  Launcher.exe
  App.config

【问题讨论】:

    标签: c# visual-studio build


    【解决方案1】:

    经过一天的挖掘和反复试验,可以使用以下解决方案为构建文件夹生成干净、自定义、样式化的层次结构。

    1) 将“probing privatePath=MyFolder”添加到项目的 App.config 文件中。

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <probing privatePath="MyFolder" />
        </assemblyBinding>
      </runtime>
    </configuration>
    

    2) 将带有“AfterBuild”的目标节点添加到您的项目文件中。 (在文本编辑器中打开您的应用程序 .csproj 文件)然后为每个在您的 .exe 旁边转储的程序集 .dll 添加一个 节点,源设置为您要移动的程序集 dll,目标设置为 $ (OutDir)\我的文件夹

    <Target Name="References" AfterTargets="AfterBuild">
      <Move SourceFiles="$(OutDir)\MyAssemblyClutter.dll" DestinationFolder="$(OutDir)\MyFolder" />
    </Target>
    

    注意: Build > Clean 不会在此之后删除您的自定义文件夹或其内容。

    对于奖励积分 (credit to Jason Morse),为确保 NuGet 包不会将其调试 .pdf 和文档 .xml 文件转储到您的发布构建文件夹中,请将以下内容添加到您的项目文件中的 '' 节点。

    <AllowedReferenceRelatedFileExtensions>
      <!-- Prevent default XML and PDB files copied to output in RELEASE. Only *.allowedextension files will be included-->
      .allowedextension
    </AllowedReferenceRelatedFileExtensions>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多