The "CompressorTask" task was not found - msbuild

Scripts.xml:
<UsingTask
TaskName="CompressorTask"
AssemblyFile="Yahoo.Yui.Compressor.dll" />
<PropertyGroup>
<JavaScriptOutputFile Condition=" '$(JavaScriptOutputFile)'=='' ">..\..\site.com\javascript\offerta.min.js</JavaScriptOutputFile>
</PropertyGroup>
<Target Name="ScriptTask">
<ItemGroup>
<JavaScriptFiles Include="..\..\site.com\javascript\offerta.js"/>
</ItemGroup>
<CompressorTask
JavaScriptFiles="#(JavaScriptFiles)"
ObfuscateJavaScript="True"
PreserveAllSemicolons="True"
DisableOptimizations="False"
EncodingType="utf-8"
DeleteJavaScriptFiles="false"
LineBreakPosition="-1"
JavaScriptOutputFile="$(JavaScriptOutputFile)"
LoggingType="HardcoreBringItOn"
ThreadCulture="en-us"
IsEvalIgnored="false" />
</Target>
I run it using a bat file:
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe Scripts.xml
pause
I'm getting:
"F:\Checkouts\Offerta\trunk\build\site.com\Scripts.xml" (default target) (1)
->
(ScriptTask target) ->
F:\Checkouts\Offerta\trunk\build\site.com\Scripts.xml(16,7): error MSB4036:
The "CompressorTask" 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 inte
rface. 3.) The task is correctly declared with in the project file,
or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framework\v2.
0.50727" directory.
What am I doing wrong? I'm using Yahoo.Yui.Compressor v1.6.0.0.zip (for .NET 3.5). Why is msbuild reporting "C:\Windows\Microsoft.NET\Framework\v2.0.50727" when I explicity run C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe?

Use Yahoo.Yui.Compressor.MsBuildTask.dll version 1.6.0.1
Unfortunaltelly this version is available only via Nuget Library
Details at: http://yuicompressor.codeplex.com/discussions/272802

Related

MSBuild not finding the DLL

I emit a console app with Mono.Cecil and I want to integrate MSBuild into the build process. But then when I run dotnet build on my custom project file, MSBuild throws an error saying Expected file "obj\Debug\net5.0\refint\test.dll" does not exist. It's trying to find the generated assembly inside the refint folder. When the assembly gets generated inside obj\Debug\net5.0\test.dll as it should. Is there a way I can change the path where MSBuild looks for the output assembly? Everything on the side of the IL generator works, I even get a runnable exe inside the build folder. Here's my project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
<DefaultLanguageSourceExtension>.ao</DefaultLanguageSourceExtension>
<OutputPath>C:\Users\filip\source\alto\samples\test\obj\Debug\net5.0\</OutputPath>
</PropertyGroup>
<Target Name="CreateManifestResourceNames" />
<Target Name="CoreCompile" DependsOnTargets="$(CoreCompileDependsOn)">
<Exec Command="dotnet run --project "$(MSBuildThisFileDirectory)\..\..\src\aoc\aoc.csproj" -- #(Compile->'$(MSBuildThisFileDirectory)', ' ') /o "#(IntermediateAssembly)" #(ReferencePath->' /r "%(Identity)"', ' ')"
WorkingDirectory="$(MSBuildProjectDirectory)" />
</Target>
</Project>
Thank you in advance.
I didn't read the whole error message.
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4527,5): error : Expected file "obj\Debug\net5.0\refint\test.dll" does not exist.
It actually points me to a file where the error was thrown. This is where:
<!-- Copy the reference assembly build product (.dll or .exe). -->
<CopyRefAssembly
SourcePath="#(IntermediateRefAssembly)"
DestinationPath="$(TargetRefPath)"
Condition="'$(ProduceReferenceAssembly)' == 'true' and '$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'"
>
<Output TaskParameter="DestinationPath" ItemName="ReferenceAssembly"/>
<Output TaskParameter="DestinationPath" ItemName="FileWrites"/>
</CopyRefAssembly>
It's trying to make a reference assembly when I don't need one. So I just set the ProduceReferenceAssembly property to false, since I don't need one.

is there a whatif switch for msbuild command line?

I have a msbuild command line running on my build server. It is deploying after build with the switch /p:DeployOnBuild=true
Is there a switch like whatif for msbuild on deploy?
There are several ways to implement the issue within continious integration.
Custom MSBuild task
You could create your own task that implements ITask interface. You could just derive your task from the helper class Task and override its Execute() method. This solution is most flexible. So, it is possible to pass additional parameters from command line to deploing process or hardcode them in dependence on build configuration.
Then add the task to your project:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Register the custom task -->
<UsingTask TaskName="TaskNamespace.MyTask" AssemblyFile="path\to\task\assembly.dll"/>
<!-- Define something -->
<!-- Set properties for Debug configuration -->
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<WhatIf>true</WhatIf>
<!-- Set another properties -->
</PropertyGroup>
<!-- Set properties for Release configuration -->
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<WhatIf>false</WhatIf>
<!-- Set another properties -->
</PropertyGroup>
<Target Name="MyTarget">
<MyTask OnlyReport="$(WhatIf)"/>
</Target>
</Project>
See detailed indormation in the Task Writing article.
Different commands
It is possible to build your project and create a web package using msbuild, then create report of the package deploying using msdeploy or .deploy.cmd file. For example
msbuild "MySolution.sln" /t:MyProject /p:Configuration="Release" /p:DeployOnBuild=true /p:PublishProfile="Local Package"
"path\to\MyProject.deploy.cmd" /T /M:"http://my-server.loc/MsDeployAgentService" /A:NTLM -allowUntrusted
The first command builds your web application project and creates local web deploy package. Note, it requires Local Package publication profile in your solution file.
The second line calls msdeploy.exe with the –whatif flag. Also it is possible to use msdeploy.exe directly. To get detailed information see Deploying Web Packages.
Automating Web Package Deployment
Previous way could be automated using <Exec> task of MSBuild. For example
<PropertyGroup>
<DeployMode>T</DeployMode>
<DeployMode Condition=" '$(Configuration)'=='Release' ">Y</DeployMode>
<DestinationServer>http://my-server.loc</DestinationServer>
</PropertyGroup>
<Target Name="PublishWebPackages">
<PropertyGroup>
<DeployCommand>
"path\to\MyProject.deploy.cmd" /$(DeployMode) /M:$(DestinationServer)/MsDeployAgentService /A:NTLM
</DeployCommand>
</PropertyGroup>
<Exec Command="$(DeployCommand)"/>
</Target>
You could also pass values of DeployMode and DestinationServer through msbuild command /p: switches.

How do I get msbuild /restore to work for a standalone/non-SDK project file?

I want to use msbuild /restore with my project file. However, my project file is more like a script which orchestrates building multiple projects with particular properties, etc. Thus, it doesn’t make sense for me to set Sdk="Microsoft.NET.Sdk" because that causes weird errors to show up. However, if I don’t specify the Sdk, the /restore is ignored and it fails to actually restore anything.
Here is my example standalone project:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="RoslynCodeTaskFactory" Version="2.0.7" />
</ItemGroup>
<Target Name="Build">
<HelloWorld/>
</Target>
<UsingTask AssemblyFile="$(RoslynCodeTaskFactory)" Condition="'$(RoslynCodeTaskFactory)' != ''" TaskFactory="CodeTaskFactory" TaskName="HelloWorld">
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
Console.WriteLine("Hello, world!");
]]>
</Code>
</Task>
</UsingTask>
</Project>
My invocation and output:
C:\Users\binki\AppData\Local\Temp>"\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe" /restore helloworld.proj
Microsoft (R) Build Engine version 15.7.177.53362 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2018-05-15 01:23:28.
Project "C:\Users\binki\AppData\Local\Temp\helloworld.proj" on node 1 (default targets).
C:\Users\binki\AppData\Local\Temp\helloworld.proj(8,5): error MSB4036: The "HelloWorld" 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 <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files 9x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64" directory.
Done Building Project "C:\Users\binki\AppData\Local\Temp\helloworld.proj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\binki\AppData\Local\Temp\helloworld.proj" (default target) (1:2) ->
(Build target) ->
C:\Users\binki\AppData\Local\Temp\helloworld.proj(8,5): error MSB4036: The "HelloWorld" 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 <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64" directory.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.71

Unable to find MSDeploy task within MSBuild

I am trying to use the MSDeploy task within MSBuild (instead of calling it form the command line). I assumed this task was built in to MSBuild but I seem to be having trouble finding the task. The error Im getting is below. I have just re-installed the Web Deploy Tool to see if it might help.
C:\CLIENTS\DAM\Components\Umbraco\SiteTemplate_v6_1_6\Build>msbuild MSBuildScript.csproj -t:Deploy_v2
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18052]
<!-- some other stuff -->
error MSB4036: The "MSDeploy" 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 imple
ments the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks
files located in the "c:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.
v10.0 can vary (v11.0 for example)
Do a search for your "Microsoft.WebApplication.targets" file and alter the import statement to match.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- Bunch of Other Stuff -->
<Target Name="AllTargetsWrapped">
<CallTarget Targets="ShowVariables" />
</Target>
<Target Name="ShowVariables" >
<Message Text="MSBuildExtensionsPath = $(MSBuildExtensionsPath)" />
</Target>

Property scope using msbuild extension pack detokenise

Im trying to use the msbuild extensions pack to fix up the configuration of our app on deploy,
i want to be able to pass a property (ENV) which will load my environment specific config file to use with the detokeniser, and fix up my application configs.
Like this:
<UsingTask TaskName="MSBuild.ExtensionPack.FileSystem.Detokenise"
AssemblyFile=".\Tools\MSBuild Extension Pack 4.0.3.0\MSBuild.ExtensionPack.dll"/>
<Import Project=".\Environments\$(Env).properties"/>
<Target Name="Build" >
<ItemGroup>
<SourceTemplates Include=".\Templates\**\*.*"/>
</ItemGroup>
<RemoveDir Directories=".\Temp"/>
<MakeDir Directories=".\Temp"/>
<Message Text="#(SourceTemplates)"/>
<Copy SourceFiles="#(SourceTemplates)"
DestinationFolder=".\Temp\%(RecursiveDir)" />
<ItemGroup>
<TargetTemplates Include=".\Temp\**\*.*"/>
</ItemGroup>
<MSBuild.ExtensionPack.FileSystem.Detokenise
TaskAction="Detokenise"
TargetFiles="#(TargetTemplates)"/>
</Target>
So i call this using
msbuild Detokenise.msbuild /p:Env=Prod
Msbuild knows about my file and i have access to its properties, but when the detokeniser runs i get the error:
Detokenise Task Execution Completed [15:07:50]
C:\Source\1.2\Build\Detokenise.msbuild(27,3):
error : InvalidProjectFileException: The imported project "C:\Source\1.2\Build\Environments\.properties" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
C:\Source\1.2\Build\Detokenise.msbuild\r
C:\Source\1.2\Build\Detokenise.msbuild(27,3): error :
All works fine if i hard code it-
Any ideas how to solve this. I thought of doing some text replacement on the msbuild before i execute...
You could try to assign this parameter to a local property:
<PropertyGroup Condition="'$(Env)'=='Prod'">
<TargetEnv>Prod</TargetEnv>
</PropertyGroup>
<!-- add other environments as needed -->
<PropertyGroup Condition="'$(Env)'=='Test'">
<TargetEnv>Test</TargetEnv>
</PropertyGroup>
<Import Project=".\Environments\$(TargetEnv).properties"/>
You could also try to enclose your parameter value in quotes:
msbuild Detokenise.msbuild /p:"Env=Prod"
As is your problem can't be reproduced, so it may be a side effect of other parameters not shown in your sample code.
I've seen a number of other questions where a similar problems was happening:
Visual Studio Ignoring MSBuild file (csproj) Customizations