Visual Studio Publish - Include folder that is not added to Project

只愿长相守 提交于 2019-12-13 15:19:35

问题


Using - VS2013, VS2015, .Net 4.5

I have several Asp.Net projects each of which has an images/books folder that contains 1000's of images. I don't include these folders in the project ( the .csproj file) files so they are always left out when using using Publish.

I want to include these folders when publishing to UAT and LIVE without having to add them to my project as having so many images in your project is problematic.

What do I need to do to make this happen?


回答1:


You can use this hook in your project file to add files or folder to deploy :

 <!--Hook to deploy add files -->
 <PropertyGroup>
      <CollectFilesFromContentDependsOn>
           AddFilesToDeploy;
           $(CollectFilesFromContentDependsOn);
      </CollectFilesFromContentDependsOn>
 </PropertyGroup>
 <!--Add files to deploy -->
 <Target Name="AddFilesToDeploy">
      <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
           <Output TaskParameter="Assemblies" ItemName="CurrentAssembly" />
      </GetAssemblyIdentity>
      <ItemGroup>
           <JsFile Include="App\MyApp.min-%(CurrentAssembly.Version).js" />
           <FilesForPackagingFromProject Include="%(JsFile.Identity)">
                <DestinationRelativePath>App\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
           </FilesForPackagingFromProject>
      </ItemGroup>
 </Target>

Warning : this hook work when you publish a web application from visual studio. This doesn't work with the publish task with Team Foundation Server because it's not the task CollectFilesFromContent that is called



来源:https://stackoverflow.com/questions/36219284/visual-studio-publish-include-folder-that-is-not-added-to-project

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