Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild Community Tasks not found

I have MyLib library project along with several examples. The library and examples are in the same solution MySolution.

In MyLib library project I have included MSBuild code to zip the whole solution and copy to another directory for internet publishing.

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
  <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
    <PropertyGroup>
      <ReleasePath>C:\Users\Administrator\Projects\CA\Libraries\Api-DotNet\</ReleasePath>
      <ZipFile>C:\Users\Administrator\Projects\CA\WebProject\libraries\Api-DotNet.zip</ZipFile>
    </PropertyGroup>
    <ItemGroup>
      <LibraryFiles Include="$(ReleasePath)\**\*.*" Exclude="$(ReleasePath)\**\*.user;$(ReleasePath)\**\*.suo;$(ReleasePath)\Api.*;$(ReleasePath)\**\packages\**;$(ReleasePath)\**\Lib.Test\**;$(ReleasePath)\**\*.nuspec;$(ReleasePath)\**\*.nupkg;$(ReleasePath)\**\*nuget*;$(ReleasePath)\**\*internal*;$(ReleasePath)\**\*ReSharper*\**;$(ReleasePath)\**\.svn\**;$(ReleasePath)\**\obj\**;$(ReleasePath)\lib\bin\Debug\**;$(ReleasePath)\lib\bin\Publish\**;$(ReleasePath)\Example\**\bin\**;" />
    </ItemGroup>
    <Zip Files="@(LibraryFiles)" WorkingDirectory="$(ReleasePath)" ZipFileName="$(ZipFile)" ZipLevel="9" />
  </Target>  
</Project>

The problem is that when user download library and run on another computer the compiler show error that import library not found MSBuild.Community.Tasks.Targets. I would like to exclude ZipAndCopy code from project file when building the solution. How to do that?

like image 220
Tomas Avatar asked Jul 24 '12 08:07

Tomas


2 Answers

Add this Condition to both the Import and the Zip elements:

Condition="Exists('$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Commu‌​nity.Tasks.Targets')"

For example:

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"
        Condition="Exists('$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Commu‌​nity.Tasks.Targets')" />

Similar to this: C# Checking if a Property 'Starts/Ends With' in a csproj

like image 67
Preet Sangha Avatar answered Sep 19 '22 14:09

Preet Sangha


The above solution hides the project file load error, but Tomas appears to be trying to use a Task from the MSBuild.Community.Tasks extension.

This should be installable by using NuGet. Here's a link to the source site showing we can install it via NuGet's Package Command Line:

PM> Install-Package MSBuildTasks

Their documentation isn't great. You'll need to also define the path using:

<Import Project="..\Packages\MSBuildTasks.1.4.0.88\tools\MSBuild.Community.Tasks.Targets"/>
<UsingTask AssemblyFile="..\Packages\MSBuildTasks.1.4.0.88\tools\MSBuild.Community.Tasks.Targets.dll"
         TaskName="MSBuild.Community.Tasks.Zip" />

...where you need to replace the Version with the Version you are using from NuGet. It's not perfect, but I managed to get mine working.

NuGet will install it into your 'Packages' folder under the root of your Solution/Project Trunk.

I ran into issues where Visual Studio may still be fighting to look for the files in a specific location. If this happens, copy the files from '.\Packages\MSBuildTasks.1.4.0.88\tools*' to 'C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\'.

This isn't the most elegant, but I was able to successfully get the new Tags to work. If I find a way to fix this last part, I'll update my posting.

like image 35
justdan23 Avatar answered Sep 19 '22 14:09

justdan23