简体   繁体   English

Service Fabric 包含其他文件

[英]Service Fabric include additional files

I have a Visual Studios solution containing the following:我有一个包含以下内容的 Visual Studios 解决方案:

  • 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".无状态服务项目使用基于配置的依赖注入,这意味着依赖与项目本身松散耦合,而不是实际的 VS“项目/编译依赖”。

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.我想继续使用 Visual Studios,但是当我部署这个项目时,它不知道程序集依赖项(因为这些仅在 DI 配置中定义),因此它不会打包必要的文件并尝试抛出异常执行依赖注入。

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 (ie my dependent assemblies) to be published to Service Fabric as part of the deployment?在 ApplicationManifest.xml 文件或 Visual Studios 提供的其他许多 XML 文件之一中,我是否可以指定其他文件(即我的依赖程序集)作为部署的一部分发布到 Service Fabric?

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.为了将此行为封装到服务项目本身中,您可以编辑服务的项目文件以包含 MSBuild 逻辑,该逻辑将 <Content> 项目动态包含到项目中,这些项目将 CopyToOutputDirectory 设置为 Always 或 PreserveNewest。 These items would be dynamically included at build time based on the configuration of your DI.这些项目将根据 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 -->
</Target>

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).您在那里的逻辑将对 DI 配置进行相同类型的读取,但它不会添加 <Content> 项,而是简单地将文件复制到应用程序包中的适当位置,其路径由 $(PackageLocation) 定义。

Using Matt's suggestion above, I got this to work in my sfproj to copy some native dlls required by my application.使用上面 Matt 的建议,我让它在我的 sfproj 中工作,以复制我的应用程序所需的一些本机 dll。 Just in case anyone has this same use case:以防万一有人有同样的用例:

<Target Name="AfterPackage" AfterTargets="Package">
    <Copy SourceFiles="ApplicationPackageRoot\mynative.dll" DestinationFolder="$(PackageLocation)\MyServicePkg\Code"/>
  </Target>

Here is the solution for the coping whole Guest Executable folder, thanks Matt and AdamC这是应对整个Guest Executable文件夹的解决方案,感谢 Matt 和 AdamC

<Target Name="AfterPackage" AfterTargets="Package">
  <ItemGroup>
    <ExamapleServiceDir Include="$(SolutionDir)\ExamapleService\**\*" />
  </ItemGroup>
  <Copy 
    SourceFiles="@(ExamapleServiceDir)" 
    DestinationFiles="@(ExamapleServiceDir->'$(PackageLocation)\ExamapleServicePkg\Code\%(RecursiveDir)%(Filename)%(Extension)')" 
    SkipUnchangedFiles="true" 
    OverwriteReadOnlyFiles="true" 
    Retries="3" 
    RetryDelayMilliseconds="300" />
</Target>
DestinationFiles="@(ExamapleServiceDir->'$(ProjectDir)\ApplicationPackageRoot\ExamapleServicePkg\Code\%(RecursiveDir)%(Filename)%(Extension)')" 

if you don't like SF complaints about Service pkg changed every publish如果您不喜欢 SF 关于 Service pkg 的投诉,则每次发布都会更改

It has a huge advantage over Content Linking because it doesn't slow down VS performance (5 sec for context window open in my project, OMG)它比内容链接具有巨大的优势,因为它不会降低 VS 性能(我的项目中打开的上下文窗口为 5 秒,OMG)

<Content Include="..\ExamapleService\**\*.*">
  <Link>ApplicationPackageRoot\ExamapleServicePkg\Code\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Content>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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