Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish additional files into bin folder

My .net web app project also includes some unmanaged dlls as additional files. These are a couple of levels deep in subfolders.

When I publish this project I need these files to be copied to the bin folder alongside all the other binaries.

No matter what settings I try, the best I can get is for them to be published into their existing folder structure which is not where I need them to be.

I've created a PostBuild event to copy the files and this works when building locally but not when publishing to a server. I've not been able to get PostPublish events to work in the same way.

Is there another way to achieve this?

Note this is similar but not the same as a previous question: Publish unmanaged DLL from referenced project

like image 393
userSteve Avatar asked Sep 19 '18 15:09

userSteve


People also ask

How do I add files to a folder in the bin?

You do this by typing executing the terminal command source ~/. profile . Copy and paste your executable into the ~/bin directory or create a link to your executable into the ~/bin directory.

How do I add files to Clickonce deployment?

On the File menu, click Open to open your application manifest. Select the Files tab. In the text box at the top of the tab, enter the directory that contains your application's files, and then click Populate. Your data file will appear in the grid.

What is Copy to Output directory?

"Copy to Output Directory" is the property of the files within a Visual Studio project, which defines if the file will be copied to the project's built path as it is. Coping the file as it is allows us to use relative path to files within the project.


2 Answers

I have a similar setup. 2 projects in my solution, one .NET Core and the other C++. When I am going to publish the dotnetcoreapp2.2 I want to include the precompiled C++ DLL from the other project. @JuanR's answer is not working for me, though it is already pretty close to my version. It looks like the <ItemGroup> needs to be in the <Target> tag.

<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
  <ItemGroup>
    <DataModelFiles Include="$(ProjectDir)..\MyCppProject\bin\Release\MyCppProject.dll" />
  </ItemGroup>
  <Copy SourceFiles="@(DataModelFiles)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="false" />
</Target>
like image 100
asdf Avatar answered Sep 21 '22 01:09

asdf


Try using an after-publish task.

You can create an item group for copy:

<ItemGroup>
  <binFilesToCopy Include="$(OutDir)\somepath\to\yourexternalDLLFolder\*" />
  <!-- Add more folders/files you want to copy here -->
</ItemGroup>

Then add a target for after publishing:

<Target Name="AfterPublish">
    <Copy SourceFiles ="@(binFilesToCopy)" DestinationFolder ="$(OutDir)\bin" />
</Target>

I did this mostly from memory so double-check for syntax, but get you the idea.

like image 44
JuanR Avatar answered Sep 21 '22 01:09

JuanR