I've set up a web application project with an additional post-build step to zip some resulting files for release builds. To do this, I've added the MSBuild Community Tasks NuGet package. This works fine when I build within Visual Studio, and I've confirmed that the zip file is created. The relevant part of the csproj file is:
<PropertyGroup>
<MSBuildCommunityTasksPath>$(SolutionDir)\.build</MSBuildCommunityTasksPath>
<ZipFile>$(SolutionName).zip</ZipFile>
</PropertyGroup>
<Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.targets" />
<Target Name="Zip" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">
<ItemGroup>
<ZipFiles Include="$(ProjectDir)\*.js; $(ProjectDir)\manifest.json" Exclude="$(ProjectDir)\*.map.js" />
</ItemGroup>
<Delete Files="$(ZipFile)" />
<Zip Files="@(ZipFiles)" WorkingDirectory="$(ProjectDir)" ZipFileName="$(ZipFile)" ZipLevel="9" />
</Target>
I have some code in another project that attempts to automatically build the above project. Here is the code:
var projectInstance = new ProjectInstance(project.File.AbsolutePath);
projectInstance.SetProperty("Configuration", "Release");
projectInstance.SetProperty("SolutionDir", project.Solution.Directory.AbsolutePath);
projectInstance.Build("Build", Enumerable.Empty<ILogger>());
The above code fails with the following error message:
The "Zip" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.
If I remove the Zip
task, it works flawlessly. Why does this fail when I build programmatically, but not when I build within VS? How can I fix it?
msbuild
command. If not, can you try that once and post the result so? – RinoTom