Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include dynamically generated files in Visual Studio's publish profile

Our build automatically bundles javascript/css files together, and adds a checksum to the name of the file for easy verification. Because these are auto-generated and the names change, I can't include them into the solution. I've tried looking through the msdn links, but I can't find a full schema for all the possible tags.

Stuff I've found but haven't been able to make sense of: How to Edit deployment settings in Publish Profile

I've also seen this answer on SO, but I haven't been able to make it work, it tries to put it in the obj folder, instead of the publish folder, and again, I can't find the schema to try and figure out how to redirect it.

Ideally, the final goal is to have the publish profile copy these files that sit under the bundles folder in the project to the bundles folder in the publish directory as specified in the PublishProfile.pubxml file.

Thank you for any help!

like image 673
Kolichikov Avatar asked May 12 '17 18:05

Kolichikov


1 Answers

I ended up finding someone with a similar issue, who helped me understand what I needed to change in the linked SO answer I ended up with the following structure, which grabs all css and js files from the root of the project (it looks like you can just invent those JSFile and CSSFile tags, they're just names to be used later), and then sending them to the DestinationRelativePath tag, which needs that %(Filename)%(Extension) bit (otherwise it just tries to create a file called bundles). JSFile.Identity seems to give a list of files.

This is what I ended up with. Notice that CSS has the RecursiveDir part, but it didn't actually do anything, and both local publish and teamcity published everything correctly.

<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="bundles\*.js" />
      <CssFile Include="bundles\*.css" />
      <FilesForPackagingFromProject Include="%(JsFile.Identity)">
        <DestinationRelativePath>bundles\%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
      <FilesForPackagingFromProject Include="%(CssFile.Identity)">
        <DestinationRelativePath>bundles\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
like image 62
Kolichikov Avatar answered Sep 18 '22 01:09

Kolichikov