本文介绍了使用Visual Studio发布在ASP.Net MVC项目外部配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.net MVC 4 Web应用程序的web.config所引用的一些其他外部配置文件(例如)。
当发布该网站唯一的web.config被公布,并没有这些外部文件将被部署。

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.

注:我已经设置的属性这些外部配置文件:BuildAction的:内容,复制总是太多,但并没有改变任何东西。

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?

感谢

推荐答案

修改您的项目文件这样:

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>

根据<α

href=\"http://stackoverflow.com/questions/2747081/how-do-you-include-additional-files-using-vs2010-web-deployment-packages\">this答案

这篇关于使用Visual Studio发布在ASP.Net MVC项目外部配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:29