EzDevInfo.com

msbuild interview questions

Top msbuild frequently asked interview questions

Resolving MSB3247 - Found conflicts between different versions of the same dependent assembly

A .NET 3.5 solution ended up with this warning when compiling with msbuild.

Sometimes NDepend might help out but in this case it didn't give any further details. Like Bob I ended up having to resort to opening each assembly in ILDASM until I found the one that was referencing an older version of the dependant assembly.

I did try using MSBUILD from VS 2010 Beta 2 (as the Connect article indicated this was fixed in the next version of the CLR) but that didn't provide any more detail either (maybe fixed post Beta 2)

Is there a better (more automated) approach?


Source: (StackOverflow)

Microsoft.WebApplication.targets was not found, on the build server. What's your solution?

Trying to build my project on the build server gives me the following error:

Microsoft (R) Build Engine Version 4.0.30319.1
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

I solved this problem a few months ago, with installing Visual Studio 2010 on the Build Server. But now I'm setup a new server from scratch, and I want to know if there any better solution to solve this issue.


Source: (StackOverflow)

Advertisements

Delphi XE custom build target is always disabled

I've created a custom MSBuild .targets file that I've included in a Delphi XE project via the IDE and enabled it from the Project Manager's context menu. Although the file validates, it always gets disabled after I re-save the project file.

Here's a simplified version of the targets file, named Custom.targets.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Hello">
    <Message Text="Hello from custom target"/>
  </Target>
</Project>

As a stand alone file this works as expected: typing...

MSBuild Custom.target /t:Hello

...at the command line gives the expected message.

Adding Custom.targets to a Delphi project via the IDE displays the file in the Project Manager as expected, and the .dproj file now contains the line...

<TargetsFile Include="Custom.targets"/>

I right-clicked the file in the IDE's Project Manager and selected Enable. But when the project is built the Build message window displays:

[MSBuild Warning] Custom.targets(1): Ignoring disabled import: PathToProjectSource\\Custom.targets

Right-clicking again in Project Manager still shows the Enable option instead of the expected Disable.

At the command line MSBuild ProjectName.dproj /t:Hello also fails.

I've tried hacking the .dproj file to add the line...

<Import Project="Custom.targets"/>

Typing MSBuild ProjectName.dproj /t:Hello now works. But the next time I save the project file from the IDE the <Import> statement gets removed.

Anyone got any idea what's going wrong please?


Source: (StackOverflow)

NAnt or MSBuild, which one to choose and when?

I am aware there are other NAnt and MSBuild related questions on Stack Overflow, but I could not find a direct comparison between the two and so here is the question.

When should one choose NAnt over MSBuild? Which one is better for what? Is NAnt more suitable for home/open source projects and MSBuild for work projects? What is the experience with any of the two?


Source: (StackOverflow)

'Specified condition "$(PackageAsSingleFile)" evaluates to "" instead of a boolean?

The visual studio 2012 on my PC get the following error message when preview in the "Public Web". I need to restart VS to get rid of the error message.

Invoke build failed due to exception 'Specified condition "$(PackageAsSingleFile)" evaluates to "" instead of a boolean. C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets'

What caused the error?


Source: (StackOverflow)

Msbuild doesn't copy references (dlls) if using project dependencies in solution

i had a look on many similar questions on this side but none of them answered the question to my problem. The whole day i tried to solve this by finding a solution (via google etc.):

I have 4 projects in my VS solution (everyone targeting .net 3.5) - for my problem only these two are important:

  1. MyBaseProject <- this class library references a 3rd party dll (elmah.dll)
  2. MyWebProject1 <- this web application project has a reference to MyBaseProject

I added the elmah.dll reference to MyBaseProject in Visual studio 2008 by clicking "Add reference..." -> "Browse" tab -> selecting the "elmah.dll".

The Properties of the Elmah Reference are as follows:

  • Aliases - global
  • Copy local - true
  • Culture -
  • Description - Error Logging Modules and Handlers (ELMAH) for ASP.NET
  • File Type - Assembly
  • Path - D:\webs\otherfolder\_myPath\__tools\elmah\Elmah.dll
  • Resolved - True
  • Runtime version - v2.0.50727
  • Specified version - false
  • Strong Name - false
  • Version - 1.0.11211.0

In MyWebProject1 i added the reference to Project MyBaseProject by: "Add reference..." -> "Projects" tab -> selecting the "MyBaseProject". The Properties of this reference are the same except the following members:

  • Description -
  • Path - D:\webs\CMS\MyBaseProject\bin\Debug\MyBaseProject.dll
  • Version - 1.0.0.0

If i run the build in visual studio the elmah.dll is copied to my MyWebProject1's bin directory, along with MyBaseProject.dll!

However if i clean and run msbuild for the solution (via D:\webs\CMS>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /t:ReBuild /p:Configuration=Debug MyProject.sln) the elmah.dll is missing in MyWebProject1's bin directory - although the build itself contains no warning or errors!

I already made sure that the .csproj of MyBaseProject contains the private element with the value "true" (that should be an alias for "copy local" in VS):

<Reference Include="Elmah, Version=1.0.11211.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\mypath\__tools\elmah\Elmah.dll</HintPath>
    **<Private>true</Private>**
</Reference>

(The private tag didn't appear in the .csproj's xml by default, although VS said "copy local" true. I switched "copy local" to false - saved - and set it back to true again - save!)

What is wrong with MSBUILD? How to get the (elmah.dll) reference copied to MyWebProject1's bin?

I do NOT want to add a postbuild copy action to every projects postbuild command! (Imagine i would have many projects depend on MyBaseProject!)


Source: (StackOverflow)

How to Publish Web with msbuild?

Visual Studio 2010 has a Publish command that allows you to publish your Web Application Project to a file system location. I'd like to do this on my TeamCity build server, so I need to do it with the solution runner or msbuild. I tried using the Publish target, but I think that might be for ClickOnce:

msbuild Project.csproj /t:Publish /p:Configuration=Deploy

I basically want to do exactly what a web deployment project does, but without the add-in. I need it to compile the WAP, remove any files unnecessary for execution, perform any web.config transformations, and copy the output to a specified location.

My Solution, based on Jeff Siver's answer

<Target Name="Deploy">
    <MSBuild Projects="$(SolutionFile)" 
             Properties="Configuration=$(Configuration);DeployOnBuild=true;DeployTarget=Package" 
             ContinueOnError="false" />
    <Exec Command="&quot;$(ProjectPath)\obj\$(Configuration)\Package\$(ProjectName).deploy.cmd&quot; /y /m:$(DeployServer) -enableRule:DoNotDeleteRule" 
          ContinueOnError="false" />
</Target>

Source: (StackOverflow)

remove nuget package restore from solution

I added the recent nuget package restore feature to a solution using 'Enable NuGet Package Restore': http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages

However it broke my build server and I didn't have the time to fix it, so I wanted to remove it. There's no option for that as far as I know, so I removed the following line manually from all my *.csproj files:

<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

The problem now is that every time my *.csproj files are checked out or open my solution, the line is automatically added again, breaking my build if I accidentally check it in :(

Any ideas how I can remove it permanently?

UPDATE: despite the answer below it still keeps coming back when opening the solution, anyone with the same problem?


Source: (StackOverflow)

What is the best practice for "Copy Local" and with project references?

I have a large c# solution file (~100 projects), and I am trying to improve build times. I think that "Copy Local" is wasteful in many cases for us, but I am wondering about best practices.

In our .sln, we have application A depending on assembly B which depends on assembly C. In our case, there are dozens of "B" and a handful of "C". Since these are all included in the .sln, we're using project references. All assemblies currently build into $(SolutionDir)/Debug (or Release).

By default, Visual Studio marks these project references as "Copy Local", which results in every "C" being copied into $(SolutionDir)/Debug once for every "B" that builds. This seems wasteful. What can go wrong if I just turn "Copy Local" off? What do other people with large systems do?

FOLLOWUP:

Lots of responses suggest breaking up the build into smaller .sln files... In the example above, I would build the foundation classes "C" first, followed by the bulk of the modules "B", and then a few applications, "A". In this model, I need to have non-project references to C from B. The problem I run into there is that "Debug" or "Release" gets baked into the hint path and I wind up building my Release builds of "B" against debug builds of "C".

For those of you that split the build up into multiple .sln files, how do you manage this problem?


Source: (StackOverflow)

Installing MSBuild 4.0 without Visual Studio 2010

I installed .NET 4.0 and VS 2010 RC on my laptop and MSBuild was automatically installed. I was hoping to build a continuous integration server by just installing the .NET SDK without VS 2010, so I downloaded the .NET 4.0 Framework from Microsoft at this link. Unfortunately, it doesn't appear to have installed MSBuild with this download (or at least I can't find it).

Is this link the appropriate link for the SDK, or is this just the runtime? If not, where is the link for the SDK?

I kind of doubt it is the entire SDK as it is only 35MB where the .NET 3.5 SP1 download was over 200MB.


Source: (StackOverflow)

This project references NuGet package(s) that are missing on this computer

I have a ASP.NET MVC5 application that worked yesterday and now I am getting this error when I try to build:

This project references NuGet package(s) that are missing on this computer.

I have the two options checked that allow nuget to automatically download and install missing packages checked / turned ON. I also have tried deleting all of the files in the packages folder and then have nuget re-download them. Also when I open nuget and look for updates it says there are none that need to be installed. I can't figure what else to do to move beyond this amazingly annoying issue.


Source: (StackOverflow)

Running MSBuild fails to read SDKToolsPath

Howdy, I'm having a bit of an issue runnning a NAnt script that used to properly build my .Net 2.0 based website, when compiling with VS2008 and it's associated tools. I've recently upgraded all the project/solution files to VS2010, and now my build fails with the following error:

[exec] C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(2249,9): error MSB3086: Task could not find "sgen.exe" using the S dkToolsPath "" or the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A". Make sure the SdkToolsPath is set and the tool exists in the correct processor specific location under the SdkToolsPath and that the Microsoft Windows SDK is installed

Now, I DO have prior versions (.Net 3.5) of the Windows SDK installed on the build server, and the full .Net 4.0 framework is installed, but I've not run across a .Net 4.0 specific version of the Windows SDK.

After a bit of experimentation and research, I finally just setup a new environmental variable "SDKToolsPath" and pointed it to the copy of sgen.exe in my windows 6.0 sdk folder. This generated the same error, but it got me to notice that even though the SDKToolsPath environmental variable IS set (confirmed that I can "echo" it at the command line and it has the expected value), the error message seems to indicated that it's not being read (note the empty quotes).

Most of the information I've found is .Net 3.5 (or earlier) specific. Not much 4.0 related out there yet. Searching for error code MSB3086 generated nothing useful either. Any idea what this might be?

Scott


Source: (StackOverflow)

Conditional Compilation and Framework Targets

There are a few minor places where code for my project may be able to be drastically improved if the target framework were a newer version. I'd like to be able to better leverage conditional compilation in C# to switch these as needed.

Something like:

#if NET40
using FooXX = Foo40;
#elif NET35
using FooXX = Foo35;
#else NET20
using FooXX = Foo20;
#endif

Do any of these symbols come for free? Do I need to inject these symbols as part of the project configuration? Seems easy enough to do since I'll know which framework is being targeted from MSBuild.

/p:DefineConstants="NET40"

Update: My question is how are people handling this situation? Are you creating different configurations? Are you passing in the constants via the command line?


Source: (StackOverflow)

Is there a good tutorial on MSBuild scripts? [closed]

I'm working on a web application project, and I need to create a build script; a build script that I can trigger from my cruisecontrol server. Since nant has not been maintained for ages, I figure that MSBuild is the way to go.

I need the build script to be able to

  • Compile all assemblies
  • Execute unit tests
  • Run NCover analysis on the unit tests
  • Deploy the database (depending on parameters). This is really executing a tool since I will end up writing my own tool to deploy the database. But the execution of the tool should be conditional based on some command line parameter.
  • Deliver unit tests and coverage results in a format that cruisecontrol can read and understand.

I assume that MSBuild will allow me to do all these things. But I don't know where to start. Does anybody know of a good tutorial to get me started with my build script?


Source: (StackOverflow)

Displaying build times in Visual Studio?

Our build server is taking too long to build one of our C++ projects. It uses Visual Studio 2008. Is there any way to get devenv.com to log the time taken to build each project in the solution, so that I know where to focus my efforts?

Improved hardware is not an option in this case.

I've tried setting the output verbosity (under Tools / Options / Projects and Solutions / Build and Run / MSBuild project build output verbosity). This doesn't seem to have any effect in the IDE.

When running MSBuild from the command line (and, for Visual Studio 2008, it needs to be MSBuild v3.5), it displays the total time elapsed at the end, but not in the IDE.

I really wanted a time-taken report for each project in the solution, so that I could figure out where the build process was taking its time.

Alternatively, since we actually use NAnt to drive the build process (we use Jetbrains TeamCity), is there a way to get NAnt to tell me the time taken for each step?


Source: (StackOverflow)