在Build and Publish中将文件添加到bin目录

wil*_*sjd 7 asp.net-mvc asp.net-mvc-4

我有两个许可文件,我希望在\bin构建发布时都包含在我的目录中.

这两个文件都在App_Data目录中(它们的初始位置无关紧要,它们只需要在其中结束\bin)并设置以下属性:

  • Build Action = Content
  • Copy to Output Directory = Copy Always

他们不是\bin我建立或发布的时候.

我的设置有什么问题:设置,文件夹,文件,还有其他什么......?

UPDATE

我将文件移出App_Data目录并将它们放在项目根目录中,现在将它们复制到\binon build.

Arv*_*tad 10

我通过稍微扩展我的.csproject文件在一些项目中完成了这个.以下代码应直接放在ProjectWebProject.csproj中的节点下.AfterBuild当从Visual Studio正常构建时,目标只是将一组文件(在这种情况下为"未引用的DLL")复制到bin文件夹.CustomCollectFiles在部署时基本上做同样的事情.

  <PropertyGroup>
    <UnreferencedDlls>..\lib\Unreferenced\**\*.dll</UnreferencedDlls>
  </PropertyGroup>
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>
  </PropertyGroup>
  <Target Name="AfterBuild">
    <Message Text="Copying unreferenced DLLs to bin" Importance="High" />
    <CreateItem Include="$(UnreferencedDlls)">
      <Output TaskParameter="Include" ItemName="_UnReferencedDLLs" />
    </CreateItem>
    <Copy SourceFiles="@(_UnReferencedDLLs)" DestinationFolder="bin\%(RecursiveDir)" SkipUnchangedFiles="true" />
  </Target>
  <Target Name="CustomCollectFiles">
    <Message Text="Publishing unreferenced DLLs" Importance="High" />
    <ItemGroup>
      <_CustomFiles Include="$(UnreferencedDlls)" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
Run Code Online (Sandbox Code Playgroud)

您需要修改的部分基本上是UnreferencedDlls与您的文件夹结构匹配的节点.该**\*.dll部分仅仅意味着"在这里的任何级别的每个DLL文件".


Kre*_*nik 7

如果您使用的是Visual Studio

  • 显示您的文件属性(单击您的文件或右键单击它然后选择Properties
  • 在“复制到输出目录”属性中,选择“始终复制”“如果更新则复制”

在构建时,文件将被复制到 bin 目录:Debug 或 Release...