Domanda

I have a web application project that references a third party assembly, which in turn uses some native dlls that it needs to find at runtime. Because of that, I wanted to add these dlls to the bin folder of the project, so that they can definitely be found.

However, if I add the files to the project in /bin/, select "copy to output", the files are compiled and published into /bin/bin. Adding them to the root folder works, but can hardly be the right solution.

Adding them to the build target "AfterBuild" has no effect when publishing (e.g. "build deployment package")

It also has to work when building the solution via TFS, where the MSBuild target _CopyWebApplicationLegacy is invoked.

È stato utile?

Soluzione

The solution was a combination of the things I had tried already:

  • Include the "Bin" folder in the project
  • Add the needed files (I added them as a link due to our development structure)
  • Set the following properties: "Build Action = Content" and "Copy to Output = Do Not Copy"

The files are now copied to the bin folder when publishing, even when automating the builds on TFS.

The component that needed this was GdPicture, which uses a couple of native DLLs during runtime.

Altri suggerimenti

It's common to have a lib folder in either your solution or workspace to put your third party dlls within. You would then add a reference to this location from your project and ensure this location is under source control.

You could also look at using NuGet to package this for you, which uses a solution level packages folder automatically.

Based on this article http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx. It's possible to define the msbuild target into main (lastest in order of solution's build) project file that will capture all files of the bin folder. Like this

<Target Name="CustomCollectFiles">
    <ItemGroup>
      <_CustomFiles Include="$(OutDir)\**\*" />
      <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>$(OutDir)\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>
  </PropertyGroup>

And place it before closing root project element.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top