Publishing external configuration files in ASP.Net MVC project using Visual Studio

大憨熊 提交于 2019-12-07 21:11:00

问题


I have a ASP.net MVC 4 web application and web.config is referencing some other external config files (e.g. ). When publishing the website only web.config gets published and none of these external files will be deployed.

Note: I have set properties of these external config file as: BuildAction : Content, Copy always too but didn't change anything!

Has anybody come up with a solution for this?

Thanks


回答1:


Modify your project file as such:

<PropertyGroup>
  <CopyAllFilesToSingleFolderForPackageDependsOn>
    CustomConfigFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
  </CopyAllFilesToSingleFolderForPackageDependsOn>

  <CopyAllFilesToSingleFolderForMsdeployDependsOn>
    CustomConfigFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
  </CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>

<Target Name="CustomConfigFiles">
  <ItemGroup>
    <YourCustomConfigFiles Include="..\Path\To\Your\**\*.config" />

    <FilesForPackagingFromProject  Include="%(YourCustomConfigFiles)">
      <DestinationRelativePath>Target\Path\For\Your\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
    </FilesForPackagingFromProject>
  </ItemGroup>
</Target>

based on this answer



来源:https://stackoverflow.com/questions/16733042/publishing-external-configuration-files-in-asp-net-mvc-project-using-visual-stud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!