Visual Studio Publish - 包含未添加到Project的文件夹

时间:2016-03-25 11:43:38

标签: visual-studio msbuild

使用 - VS2013,VS2015,.Net 4.5

我有几个Asp.Net项目,每个项目都有一个包含1000张图像的图像/书籍文件夹。我没有在项目(.csproj文件)文件中包含这些文件夹,所以在使用Publish时它们总是被忽略。

我希望在发布到UAT和LIVE时包含这些文件夹,而不必将它们添加到我的项目中,因为项目中有如此多的图像存在问题。

我需要做些什么来实现这一目标?

1 个答案:

答案 0 :(得分:3)

您可以在项目文件中使用此挂钩添加要部署的文件或文件夹:

 <!--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>

警告:当您从visual studio发布Web应用程序时,此挂钩会起作用。这不适用于Team Foundation Server的发布任务,因为它不是被称为CollectFilesFromContent的任务