Copying Build Artifacts for Visual Studio MSBuild

Lately, I’ve been working to integrate a client-side build process to a project at work.  The idea is that I would like to be able to transpile my TypeScript files through webpack and include them in my published solution.

I added my webpack build command to the pre-build commands section in my web project and thought that I would be good to go. Nope.

I ran into a road block.  Build artifacts (like my output folder that webpack puts all of the transpiled files into) don’t automatically get pushed out on publish of the web project.

After a long while testing out ideas to no avail, I finally found a solution.

If you add this target near the end of your web.csproj file, it’ll add your output directory to your published solution. (note: TypeScriptCompiledToJS was my output directory that I wished to get pushed to the published output.  You could change that in this solution to whatever name you need.)

<Target Name=”CopyTypeScript”>
<Message Text=”Copy Typescript Files” Importance=”high” />
<ItemGroup>
<_CustomFiles Include=”$(ProjectDir)\TypeScriptCompiledToJS\**\*” />
<FilesForPackagingFromProject Include=”%(_CustomFiles.Identity)”>
<DestinationRelativePath>TypeScriptCompiledToJS\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<PipelineCollectFilesPhaseDependsOn>
CopyTypeScript;
$(PipelineCollectFilesPhaseDependsOn);
</PipelineCollectFilesPhaseDependsOn>
</PropertyGroup>

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: