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:

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?

Was it helpful?

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top