No MSBuild Community Tasks Found

I have a MyLib library MyLib and some examples. The library and examples are in the same MySolution solution.

In the MyLib library MyLib I included the MSBuild code to consolidate the entire solution and copy it to another directory for publishing on the Internet.

 <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 the user loads the library and runs on another computer, the compiler shows an error that does not import the MSBuild.Community.Tasks.Targets library. I would like to exclude the ZipAndCopy code from the project file when creating the solution. How to do it?

+9
c # visual-studio-2010 msbuild
source share
4 answers

It looks like you need several build configurations. I would suggest setting it up specifically for creating and archiving artifacts and individual ones for your users.

Release ZIP can be your build with a post-build event for zip files, and Release can be a regular build that does nothing special using community tasks.

+3
source share

Add this Condition to the Import and 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 # Verifying that the property “Starts / Ends with” in csproj

+8
source share

The above solution hides the error of loading the project file, but Tomas seems to be trying to use Task from the MSBuild.Community.Tasks extension.

This must be installed using NuGet. Here is a link to the source site showing that we can install it through the command line of the NuGet package:

 PM> Install-Package MSBuildTasks 

Their documentation is small. You also need to determine 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 that you are using from NuGet. This is not perfect, but I managed to get it to work.

NuGet will install it in the Packages folder under the root of your Solution / Project trunk.

I ran into problems when Visual Studio could still struggle to find files in a specific place. If this happens, copy the files from '. \ Packages \ MSBuildTasks.1.4.0.88 \ tools *' to 'C: \ Program Files (x86) \ MSBuild \ MSBuildCommunityTasks \' .

This is not the most elegant, but I was able to successfully use the new tags. If I find a way to fix this last part, I will update the message.

+3
source share

This is the solution! Big! Thanks!

0
source share

All Articles