tommed tommed - 3 months ago 76
C# Question

Service Fabric include additional files

I have a Visual Studios solution containing the following:

  • Service Fabric project

  • Stateless Service Project

The stateless service project uses configuration-based dependency injection, meaning the dependencies are loosly coupled with the project itself and not actual VS "project/compilation dependencies".

I would like to continue to use Visual Studios, but when I deploy this project it doesn't know about the assembly dependencies (as these are only defined in DI configuration) and therefore it doesn't package up the necessary files and throws exceptions trying to perform dependency injection.

Is there any way in the ApplicationManifest.xml file or one of the other many XML files that Visual Studios provides that I can specify additional files (i.e. my dependent assemblies) to be published to Service Fabric as part of the deployment?

Ideally, I'd like to automate this file to be generated as part of my automated build script.


In order to encapsulate this behavior into the Service project itself, you could edit the service's project file to include MSBuild logic which dynamically includes <Content> items to the project that have CopyToOutputDirectory set to Always or PreserveNewest. These items would be dynamically included at build time based on the configuration of the your DI. Since the service project is "declaring" that it has these content items, they will be copied to the service's package folder.

Another option is to add logic at the Application project during the Package step. You can implement a target there like this:

<Target Name="AfterPackage" AfterTargets="Package">
  <!-- Copy dependency files to service package location -->

Your logic there would do the same type of reading of your DI configuration but, rather than adding <Content> items, it would simply copy the files to the appropriate location within the application package whose path is defined by $(PackageLocation).