Adding excluded files to publish
-
08-02-2021 - |
Question
I am working on a SharePoint project using VS2019.
When I publish the project, I need to add additional some files to the wsp
file. These files are excluded from the project.
I have been looking at the Package.package
thing, but without luck so far.
I tried to add the following to the manifest without success:
<TemplateFiles>
<TemplateFile Location="Layouts\Angular\*"/>
</TemplateFiles>
I have been looking at the following resources in an attempt to make progress:
- https://docs.microsoft.com/en-us/visualstudio/sharepoint/merging-xml-in-feature-and-package-manifests?view=vs-2019
- https://docs.microsoft.com/en-us/visualstudio/sharepoint/how-to-add-and-remove-additional-assemblies?view=vs-2019
- https://docs.microsoft.com/en-us/visualstudio/sharepoint/how-to-create-a-sharepoint-solution-package-by-using-msbuild-tasks?view=vs-2019
I get a feeling I may have to use msbuild
, but I have not worked with it before. Perhaps someone can confirm that it is the only way to make it work?
Solution
So, I found out the Package file did not matter. It needed to be solved using msbuild
.
It was practically impossible to figure out how to get my hands on msbuild
, as it seems heavily embedded into Visual studio nowadays...
Tools -> Command Lines -> Developer PowerShell
Bam, you now have msbuild
!
My problem was, that I needed to include some generated files, but touching the *.csproj
file was not viable as Visual Studio regularly would override my changes...
*.targets
files to the rescue!
I created the following file (CustomBuildProcess.targets
) at the root of my project:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Content Include="Layouts\Angular\**\*" Importance="High"/>
</ItemGroup>
</Project>
And imported it in the *.csproj
file as so:
<Import Project="$(ProjectDir)\CustomBuildProcess.targets" />
I just dumped the above line next to another Import line - specifically this one:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
After making these small changes, running the following command from the developer powershell was all the magic I needed:
$ msbuild [*.csproj] /t:Package
And now my Angular files are included in the *.wsp
file while still being "excluded" in Visual Studio.
Lastly, a huge shout out to this wordpress website I found after roughly 10 hours of googling: https://chrisa.wordpress.com/2014/07/18/customising-your-build-process/