问题
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