简体   繁体   中英

Copy folder to publish locations bin folder

In the Visual Studio solution explorer it is possible to set "Build action" and "Copy To Output Directory" for files when viewing the file properties:

在此处输入图像描述

My question is: How can I tell Visual Studio to copy the complete folder and sub folder/files to the output directory?

If I view the properties of the folder the options are not there:

在此处输入图像描述

I tried using a post build command:

XCOPY "$(SolutionDir)Lib/XULRunner21_0" "$(OutDir)XULRunner21_0/" /E /I /F /Y
XCOPY "$(SolutionDir)Lib/ABCGecko.dll" "$(OutDir)" /E /I /F /Y

The files are copied before compiling, but not during publishing so that does not work.

I know this question is very old, but I struggled to find a solution when this should be easy enough. If you want to copy a folder to the Publish directory, with all the files inside, you can do the following in the .csproj file:

<Target Name="CopyYourFolderAfterPublish" AfterTargets="Publish">
    <Exec Command="XCOPY $(ProjectDir)YourFolder\*.* $(PublishDir)\YourFolder\ /S /Y" />
</Target>

Now, YourFolder will appear in the publish folder. This was tested using .NET6 and VS 2022.

You need to set the Build action for each file to "Content". Then they will be distributed to the output folder (any the sub folder in your project where they are located will also be created under the output folder)

You can arbitrarily extend your build process as described here: http://msdn.microsoft.com/en-us/library/ms366724.aspx

For example, in your project file:

<Target Name="BeforePublish">
  <Exec Command="XCOPY ..." />
  <Exec Command="XCOPY ..." />
</Target>

Sorry: I have just seen your last comment ("The files are copied before compiling, but not during publishing so that does not work."), so publishing problem still exists. However; We should be able to extend the visual studio build process for BeforePublish and AfterPublish target names in order to fix publishing problem as described here.

This is how you can tell Visual Studio to copy the complete folder and sub folder/files to the output directory.

First add your folder(This is my folder XULRunner21_0) to your project with all the items added to your project, and then go to your project's Properties>Build Events and write the following command line into Post-build event command line area. After building the solution, you should see under bin folder of your project XULRunner21_0 folder will be created with all the items in it.

That is all, hope it helps.

xcopy /E /Y "$(ProjectDir)XULRunner21_0\*" "$(ProjectDir)$(OutDir)XULRunner21_0\"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM