Having trouble getting MSBuild and MSBuildCommunityTasks (VSS) to work together - msbuild

I am trying to learn how to do certain source control tasks with VSS and MSBuildCommunityTasks, like how to use tasks like GetVSS and VssLabel? Docs don't make this clear. And when I poke a stick at it to see if the error messages can tell me anything, it isn't really very clear what to do then, either. Let me show what I'm doing and what I'm getting -- I hope someone can point me in the right direction.
Project is written in C# using VS2005. Here's the MSBuild project file source:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Target Name="GetLatestVersionVSS">
<VssGet DatabasePath="C:\VSS\Astronom_VSS"
Path="$/Astronom_VSS"
LocalPath="C:\VisualStudioSource\AstronomySolution\Astronom" UserName="build" Password="build" />
</Target>
<Target Name="Compile" DependsOnTargets="GetLatestVersionVSS">
<MSBuild Projects="Astronomer.x.csproj" />
</Target>
</Project>
I get error messages as follows:
Target GetLatestVersionVSS:
C:\Documents and Settings\michaelc\My Documents\Visual Studio 2005\Projects\Astronom\Astronomer\msbuild_UseVSS.xml(7,5):
error MSB4018: The "VssGet" task failed unexpectedly.
C:\Documents and Settings\michaelc\My Documents\Visual Studio 2005\Projects\Astronom\Astronomer\msbuild_UseVSS.xml(7,5):
error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly
'Microsoft.VisualStudio.SourceSafe.Interop, Version=5.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
or one of its dependencies. The system cannot find the file specified.
C:\Documents and Settings\michaelc\My Documents\Visual Studio 2005\Projects\Astronom\Astronomer\msbuild_UseVSS.xml(7,5):
error MSB4018: Filename: 'Microsoft.VisualStudio.SourceSafe.Interop, Version=5.2.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
...And so on.
It occurs to me that I might need to put some sort of Import item in there to point to VSS, specifically to point to Microsoft.VisualStudio.SourceSafe.Interop, but I cannot find a .dll file by that name, and it is not in the list of components in the .NET tab of the Add Reference dialog in Visual Studio.

OK, I am answering my own question.
MSBuildCommunityTasks requires Visual Source Safe 2005, which ships with VS2005. We are, however, still using VSS 6.0d, and MSBuildCommunityTasks does not work with it. The developer's guide for the tasks states:
Developer's Guide for http://msbuildtasks.tigris.org/
=====================================================
Build Environment Prerequisites
------------------------------
- .NET2.0
- MSBuild; typically already installed as part of .NET2.0,
for example in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe
- NUnit 2.2.X (http://www.nunit.org/);
necessary to run the tests
- Microsoft Visual SourceSafe(R) 2005;
the library Microsoft.VisualStudio.SourceSafe.Interop gets referenced
- NDoc 1.3 (http://ndoc.sourceforge.net/)
additionally configure NDoc to use .NET2; see
http://ndoc.sourceforge.net/wiki/dotNet_2.0_Support
- Microsoft Visual Studio 2005 as IDE

Related

TFS 2015 reference required to assemby

I've a problem with a build with TFS 2015.
I've a simple project that reference B.dll . B.dll use A.dll . The project don't reference A.dll as it don't use it itself.
A.dll & B.dll bothe are company Framework dll stored in the GAC.
[error]LogistiqueTest\Index.aspx.vb(7,14): Error BC30009: Reference required to assembly 'A.DII.Technique.Interfaces, Version=3.5.0.0, Culture=neutral, PublicKeyToken=e60618ca32d203a8' containing the implemented interface 'A.DII.Technique.Interfaces.IGestionException'. Add one to your project.
This is not a big deal, just a reference that's missing. But we don't want to add unecessary references in our projects
Moreover, this problem don't occurs with visual studio (2013 pro)
So I tracked the problem and I saw that :
-> Visual studio retrieve quickly the reference (A.dll) after the "call" of this line
Target "CoreBuild: (TargetId:61)" in file "C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets" from project "D:\AgentTFS_02_work\3\s\LogistiqueTest\LogistiqueTest.vbproj" (target "Build" depends on it):
But TFS don't use the same file; it use
"C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets"
The difference between those files is in Microsoft.Common.CurrentVersion.targets, there is some code for resolving assemblies.
So my questions are, is there a way to make TFS build my solution visual studio like ? Force the other target file to be used? Is there another trick to be able to resolve this assembly ?
I tried to add, like i saw in many post around the web, a folder that contains every .dll required, but TFS don't event try to resolve path for A.dll
More information : The exception occurs at the execution of Vbc.exe
because with VS execution the command line has A.dll in the /import section when with TFS it's not added. No problems with MSBuild.exe.
I finally found an anwser :
http://www.nsilverbullet.net/2012/02/17/automatically-resolving-secondary-assembly-references-with-msbuild-and-tfs-build/
I need to add this to the proj file that has problems.
<Target Name="AfterResolveReferences">
<!-- Redefine referencepath to add dependencies-->
<ItemGroup>
<ReferencePath Include="#(ReferenceDependencyPaths)"></ReferencePath>
</ItemGroup>
</Target>

Prevent installation of VSTO Addin on build

How to prevent background installation of VSTO Outlook Addin on build in Visual Studio?
Addin installed when build/rebuild project or solution. Installed addin is not even shown in Programs and Features.
Addin installed when build/rebuild project or solution. Installed addin even not shown in Programs and Features.
The add-in is not actually installed. It is registered, see Registry Entries for Application-Level Add-Ins for more more information.
You may try to add a post-build action to remove the registry keys to prevent it from loading (or just change the LoadBehavior key).
I'm targeting a specific purpose. My client build machine projects fail when they build the same VSTO-projects from different Git-branches simultaneously.
VSTO-project tries to register its MS Office add-in to the Windows Registry during building.
If some VSTO-projects are building simultaneously then a Windows async exception can be thrown. See the exception below.
Of course won't see this error in Visual Studio. Commonly, you're building one solution at a time. This is the source of this evil bug.
With a due respect to the question's authors and future comers, let me post some "preliminary to build-machines" solutions.
I can't test them for an VSTO Outlook Add-in project. But they are tested for MS Word and Excel add-ins.
Actually, the Outlook project is slightly special. If something goes wrong with it, then you can learn MSBuild and dig farther out of
C:\Program Files (x86)\Microsoft Visual Studio\20<XX>\Professional\MSBuild\Microsoft\VisualStudio\v<XX>.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets
Hack MSBuild Task.
We will be using MSBuild Inline Tasks approach.
Let's do it for MS Word and Excel Add-ins.
For the Outlook VSTO, you have to override more tasks. Probably the RegisterFormRegions, FindRibbons, etc. I just can't test it.
In the Solution Explorer, click "Clean" on your VSTO Add-in project to delete previous registrations.
then do "Unload Project" on your project.
Edit {You-Project-Name}.csproj from the context menu on you project in the Solution Explorer.
Find <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets"
Before (!!!) this Import row, insert the following XML of my inline MSBuild task.
<UsingTask
TaskName="SetOffice2007AddInRegistration"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<Url ParameterType="System.String" Required="false"/>
<AddInName ParameterType="System.String" Required="false"/>
<OfficeApplication ParameterType="System.String" Required="false"/>
<FriendlyName ParameterType="System.String" Required="false"/>
<Description ParameterType="System.String" Required="false"/>
<LoadBehavior ParameterType="System.String" Required="false"/>
<Unregister ParameterType="System.String" Required="false"/>
<SolutionID ParameterType="System.String" Required="false"/>
<IsDocument ParameterType="System.String" Required="false"/>
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage(MessageImportance.High, "$(MSBuildProjectName) project - Overriding of SetOffice2007AddInRegistration to prevent the project's MS Office Add-in isntallation (registration)!");
]]>
</Code>
</Task>
</UsingTask>
Click Reload Project on your Add-in's project.
That's it.
You can also use C# and mock or derive from the existing C# class of SetOffice2007AddInRegistration task. But this will be quite verbose for the StackOverflow.
Hack the VisualStudioForApplicationsBuild Target
Everything is changing and VSTO is rather dead than alive.
So, why don't you copy <Target Name="VisualStudioForApplicationsBuild">...</Target> from the mentioned above Microsoft.VisualStudio.Tools.Office.targets file and override it in your VSTO add-in project file?
Put it below the <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" and do what ever you want.
Hack the RegisterOfficeAddin MSBuild target
This is for MS Word and Excel add-ins only.
As described above, find <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets".
and put below (!!!)
<Target Name="RegisterOfficeAddin" Condition ="'$(VSTO_ProjectType)' == 'Application'" />
More, More
Actually, there are other MSBuild approaches. But who bothers?
Hack on my laptop only
Sorry, this is out of my orbit, really :)
But knowing MSBuild, you can do it for a Windows login name or for an exact PC name. Just for fun. Why not use the MSBuild Inline Tasks as described above?
Build Machines
Let's prevent VSTO Add-ins installation/registration caused by VSTO Add-in project building.
The following works for MS Word and Excel VSTO Add-in projects.
Add -p:Disable_RegisterOfficeAddin=disable to your invocation of MSBuild
CMD example
CALL "%env_manager%\MSBuild_Wrapper_VS2017.bat"^
MySolution.sln^
-target:Build^
-p:Configuration=Release^
-p:Disable_RegisterOfficeAddin=disable^
-verbosity:%env_MsBuild_verbosity%^
-maxCpuCount
Edit ".csproj" file of your VSTO Add-in project.
find <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets"
row and put below (!!!) it the following XML.
<!-- Prevent VSTO MS Office add-ins installation/registering during building of VSTO-projects on build machines. -->
<Target Name="RegisterOfficeAddin" Condition ="'$(VSTO_ProjectType)' == 'Application'">
<Message Text="RegisterOfficeAddin target is redefined in $(MSBuildProjectName) project" Importance="high" />
<SetOffice2007AddInRegistration
Url="$(AbsolutePathToTheDeploymentManifest)"
AddInName="$(TargetName)"
OfficeApplication="$(OfficeApplication)"
FriendlyName="$(FriendlyName)"
Description="$(OfficeApplicationDescription)"
LoadBehavior="$(LoadBehavior)"
Condition="'$(Disable_RegisterOfficeAddin)' != 'disable'"
/>
<Message Text="SetOffice2007AddInRegistration task is suppressed in $(MSBuildProjectName) project" Condition="'$(Disable_RegisterOfficeAddin)' == 'disable'" Importance="high" />
<Message Text="as Disable_RegisterOfficeAddin parameter is $(Disable_RegisterOfficeAddin)" Condition="'$(Disable_RegisterOfficeAddin)' == 'disable'" Importance="high" />
</Target>
The Exception
Let me provide you with my full exception from VSTO-project building
The "SetOffice2007AddInRegistration" task failed unexpectedly.
System.IO.IOException: Illegal operation attempted on a registry key that has been marked for deletion.
BTW, there are no "Clean Project" commands in my build processes.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: The "SetOffice2007AddInRegistration" task failed unexpectedly. [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: System.IO.IOException: Illegal operation attempted on a registry key that has been marked for deletion. [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.VisualStudio.Tools.Office.Runtime.AddInRegistryKeyManager.CreateKey(RegistryKey rootKey, String url, String addInName, String officeApplication, String friendlyName, String description, Int32 loadBehavior) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.VisualStudio.Tools.Office.Runtime.AddInRegistryKeyManager.RegisterAddIn(OfficeSolutionMetadata parser) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.VisualStudio.Tools.Office.Runtime.AddInRegistryKeyManager.RegisterAddIn(Uri manifestUri, String addInName, String officeApplication, String friendlyName, String description, Int32 loadBehavior, String compatibleFrameworkXML, Boolean runLocal) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.VisualStudio.Tools.Office.BuildTasks.SetOffice2007AddInRegistration.Execute() [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() [C:\Build-Machine\My\Build\Source\MyAddin.csproj]

MSBuild unable to find metadata file for PresentationCore

I am writing a MSBuild file for one of my .NET projects. I do not want to use the Visual Studio generated .sln and .csproj files for certain reasons. I am also aiming to get some experience writing my own build files.
One of my source files is referencing the System.Windows.Media namespace and the build failed with the below message
error CS0234: The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
So I added the following snippet in my build file...
<ItemGroup>
<Reference Include="PresentationCore">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
I made changes in the CSC task as follows...
<Target Name="ReleaseBuild">
<MakeDir Directories="$(ReleaseDir)"/>
<Csc Sources="#(SrcFile)"
OutputAssembly="$(ReleaseDir)\$(OutputAssemblyName)"
TargetType="Library"
References="#(Reference);
$(LibDir)\MyOwnLib.DLL"
Platform="$(ProcessorPlatform)">
</Csc>
</Target>
only to get the following error - CSC : error CS0006: Metadata file 'PresentationCore' could not be found
Why is MSBuild not able to find the PresentationCore assembly in the GAC? Is there some additional version information that I should give? I searched in many forums but seem to be going around in circles and I would be glad for any useful pointers as to what the problem could be.
I am using MSBuild 4.0 on an x64 machine and building for an x86 target. My build files which referenced only the MS core libraries worked fine. My VS2008 projects also build fine.
Some Progress
I was able to progress in this issue by making the following changes...
1) I added a property to specify the path of the presentation core library - <PresentationCoreLibDir>C:\Windows\Microsoft.NET\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35</PresentationCoreLibDir>
2) Added an additional parameter to the CSC task like this - AdditionalLibPaths="$(PresentationCoreLibDir)"
3) Finally appended the .DLL suffix to the reference tag -
<ItemGroup>
<Reference Include="PresentationCore.DLL">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
I am relieved that I was able to get around this, but is there a neater way of doing this? I thought that the MSBuild engine would be able to figure this out in a more seamless way. Can anyone throw more light on this?
For x86 make sure you use the correct MSBuild which should be at:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
Rather than the x64 MSBuild that is located at:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe

How to use YUI Compressor.Net MSBuild Task 2.3.0.0

I have tried searching the web for a solution to this problem but it seems very unclear. It sounds like people are seeing this but the solutions don't seem to work for me.
I have downloaded and installed YUICompressor.NET.MSBuild 2.3.0.0 from NuGet into my project.
I have created an MSBuild target file that closely resembles the example file included and exists as part of my .csproj file so I can run it in the AfterBuild step.
I am getting the following error everytime I try to build my VS project:
The "JavaScriptCompressorTask" task could not be loaded from the assembly SolutionDir\packages\YUICompressor.NET.MSBuild.2.3.0.0\lib\NET20\Yahoo.Yui.Compressor.Build.MsBuild.dll.
Could not load file or assembly 'Yahoo.Yui.Compressor, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
My folder structure is as follows:
\Solution
\packages
YUICompressor.NET.MSBuild.2.3.0.0\lib\NET20\
\build
ProjectFile.csproj
In the csproj I have:
<UsingTask TaskName="CssCompressorTask" AssemblyFile="packages\YUICompressor.NET.MSBuild.2.3.0.0\lib\NET20\Yahoo.Yui.Compressor.Build.MsBuild.dll" />
<UsingTask TaskName="JavaScriptCompressorTask" AssemblyFile="packages\YUICompressor.NET.MSBuild.2.3.0.0\lib\NET20\Yahoo.Yui.Compressor.Build.MsBuild.dll" />
<Target Name="AfterBuild">
<ItemGroup>
<JavaScriptFiles Include="someFile.js" />
</ItemGroup>
<JavaScriptCompressorTask SourceFiles="#(JavaScriptFiles)" OutputFile="build\combined.js" DeleteSourceFiles="false" CompressionType="None" ObfuscateJavaScript="false" PreserveAllSemicolons="true" />
<JavaScriptCompressorTask SourceFiles="#(JavaScriptFiles)" OutputFile="build\combined.min.js" DeleteSourceFiles="false" CompressionType="Standard" />
</Target>
Am I missing something? Can anyone help me? Thank you.
Did you try to download version 2.3.0.0 directly from codeplex? Then make sure that the Yahoo.Yui.Compressor.Build.MsBuild.dll and Yahoo.Yui.Compressor.dll reside in the same directory. Like this I was able to make it work.
It's been a while since i've played around with the AfterBuild .. but how this works is that the the msbuild program is ran from some directory .. and therefore looks for those assembly files RELATIVE to where the msbuild is being executed from.
I'm not sure if this means the msbuild is being run from C:\program files(x86)\Microsoft Visual Studio\<whatever...>
TAKE NOTE: it's the folder/path (aka execution path) where visual studio is running the msbuild command from ... NOT where msbuild exists.
So therefore, it can't find the assemblies.
Try putting in the full path to the assemblies (just to see if that works).
eg. C:\Projects\Solution\packages\YUICompressor.NET.MSBuild.2.3.0.0\lib\NET20\Yahoo.Yui.Compressor.Build.MsBuild.dll
If it's running it from the \solution\bin directory, then you're in luck! cause then you can do ..\packages\YUICompressor.NET.MSBuild.2.3.0.0\lib\NET20\Yahoo.Yui.Compressor.Build.MsBuild.dll' (the..means: from thisbindirectory, go up one level tosolutionthen down intopackagesand then down intoYUIComp`... etc.
So the answer to your question is this: Find the location Visual Studio is running the msbuild command from, during an AfterBuild. Maybe put in some code in there to say 'write to file => current path i'm in :P'

Overriding MSBuildExtensionsPath in the MSBuild task is flaky

This is already cross-posted at MS Connect:
https://connect.microsoft.com/VisualStudio/feedback/details/560451
I am attempting to override the property $(MSBuildExtensionsPath) when building a solution containing a C# web application project via msbuild. I am doing this because a web application csproj file imports the file "$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets". This file is installed by Visual Studio to the standard $(MSBuildExtensionsPath) location (C:\Program Files\MSBuild). I would like to eliminate the dependency on this file being installed on the machine (I would like to keep my build servers as "clean" as possible). In order to do this, I would like to include the Microsoft.WebApplication.targets in source control with my project, and then override $(MSBuildExtensionsPath) so that the csproj will import this included version of Microsoft.WebApplication.targets. This approach allows me to remove the dependency without requiring me to manually modify the web application csproj file.
This scheme works fine when I build my solution file from the command line, supplying the custom value of $(MSBuildExtensionsPath) at the command line to msbuild via the /p flag. However, if I attempt to build the solution using the MSBuild task in a custom msbuild project file (overriding MSBuildExtensionsPath using the "Properties" attribute), it fails because the web app csproj file is attempting to import the Microsoft.WebApplication.targets from the "standard" Microsoft.WebApplication.targets location (C:\Program Files\MSBuild). Notably, if I run msbuild using the "Exec" task in my custom project file, it works. Even more notably, the FIRST time I run the build using the "MSBuild" task AFTER I have run the build using the "EXEC" task (or directly from the command line), the build works.
Has anyone seen behavior like this before? Am I crazy? Is anyone aware of the root cause of this problem, a possible workaround, or whether this is a legitimate bug in MSBuild?
Steps to Reproduce:
1) Create a new empty solution in MSVS 2008 (Fake.sln)
2) Add a new C# web application to the solution (WebApplication1.csproj)
3) Close MSVS
4) Copy the contents of "C:\Program Files\MSBuild\" to a directory called "MSBuildExtensions" in the directory containing your solution.
5) rename the directory "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications" so that WebApplication1.csproj will not be able to import Microsoft.WebApplication.targets from that location.
6) Create a custom MSBuild project file called "TestBuild.proj" in the same directory as the solution. It should have the following content:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="BuildMSBuild">
<PropertyGroup>
<MSBuildExtensionsPath>$(MSBuildProjectDirectory)\MSBuildExtensions\</MSBuildExtensionsPath>
<BuildThis>Fake.sln</BuildThis>
</PropertyGroup>
<Target Name="BuildMSBuild">
<MSBuild Projects="$(BuildThis)" Properties="MSBuildExtensionsPath=$(MSBuildExtensionsPath);" Targets="Clean" />
<MSBuild Projects="$(BuildThis)" Properties="MSBuildExtensionsPath=$(MSBuildExtensionsPath);"/>
</Target>
</Project>
7) execute "msbuild TestBuild.proj" from a MSVS command prompt (note: the build may succeed the first time, but will fail if you run more than once)
Did you try setting the environment variable MSBuildExtensionPath in the CMD prompt and then running your build?
For example:
C:\> SET MSBuildExtensionsPath=C:\My\MSBuild\Extensons
Then on this project file:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Text='MSBuildExtensionsPath="$(MSBuildExtensionsPath)"' />
</Target>
</Project>
you will get the following output:
c:\Users\chuckeng\Desktop\ConsoleApplication1>"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" my.proj
Microsoft (R) Build Engine Version 3.5.30729.4926
[Microsoft .NET Framework, Version 2.0.50727.4927]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 6/25/2010 1:04:05 PM.
Project "c:\my.proj" on node 0 (default targets).
MSBuildExtensionsPath="C:\My\MSBuild\Extensons"
Done Building Project "c:\my.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.03
This works from v4.0 as well. Although, support is generally better in v4.0 for things like this. And, v4.0 is 100% backward compatible (bugs not withstanding). So, you can build your v3.5 and prior projects with v4.0. Just select ToolsVersion 3.5.
msbuild my.proj /tv:3.5
Hope this helps...
Chuck England
Visual Studio
Program Manager - MSBuild
This is a bug in MSBuild 3.5 but it is fixed in MSBuild 4.
If you can, switch to MSBuild 4 (you still can compile your 3.5 projects), otherwise you'll have to override the property in the project file.
It works fine if you override MSBuildExtensionsPath directly in the web app .csproj file.
<PropertyGroup>
<MSBuildExtensionsPath>C:\Users\madgnome\Desktop\msbuild</MSBuildExtensionsPath>
<!-- It works too with relative path -->
<!--<MSBuildExtensionsPath>..\msbuild</MSBuildExtensionsPath>-->
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
Don't know if this might help anyone in the future, but I was able to use the following at the top of my file and it works as I would expect in both 32 and 64 bit build environments.
<PropertyGroup>
<MSBuildExtensionsPath Condition=" '$(MSBuildExtensionsPath64)' != '' ">$(MSBuildExtensionsPath64)</MSBuildExtensionsPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>