Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't build our solution with MSBUILD, it can't find our .targets files

I've written some windows batch files to call msbuild for all of the VS solutions that our product consists of.

They all work except one SLN, in which to CSPROJ files are causing problems.

The projects all build in VS2008.

PROJECT FOLDER LAYOUT

\RootFolder
   \LinqToXsd
     -LinqToXsd.targets
     -Xml.Schema.Linq.dll
   \BL
     -BL.csproj
   \Config
     -Config.csproj

We have customized the CSPROJ files to pull in LinqToXsd:

Added this line to the first PropertyGroup:

<LinqToXsdBinDir Condition="'$(LinqToXsdBinDir)' == ''">$(SolutionDir)\..\LinqToXsd</LinqToXsdBinDir>

And this line after the Import for Microsoft.CSharp.targets

<Import Project="$(LinqToXsdBinDir)\LinqToXsd.targets" />

Command Line:

C:\Windows\Microsoft.NET\Framework64\v3.5\msbuild.exe /m /target:Build /nologo /property:BuildInParallel=true;OutDir=E:\Projects\BuildMaster\trunk\built\ConfigTool\;Configuration=Release /verbosity:minimal "*snip*\ConfigTool\ConfigTool.sln"

Problem is, we get this in the output:

*snip*\ConfigTool\ConfigTool.csproj(131,11): error MSB4019: The imported project "E:\LinqToXsd\LinqToXsd.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
ConfigTool.csproj : Solution file warning MSB4122: Scanning project dependencies for project "ConfigTool.csproj" failed. The imported project "E:\LinqToXsd\LinqToXsd.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  *snip*\ConfigTool\ConfigTool.csproj
*snip*\BL\BL.csproj(352,11): error MSB4019: The imported project "E:\LinqToXsd\LinqToXsd.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
..\BL\BL.csproj : Solution file warning MSB4122: Scanning project dependencies for project "..\BL\BL.csproj" failed. The imported project "E:\LinqToXsd\LinqToXsd.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  *snip*\BL\BL.csproj
C:\Windows\Microsoft.NET\Framework64\v3.5\Microsoft.Common.targets : warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Xml.Schema.Linq". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

Yet I've got other projects that use those lines and work perfectly. Including ones that reference the same CSPROJ files (share BL).

I've tried deleting all the bin, obj, cache, suo and user files/folders, no difference.

Any msbuild experts out there that can help?

Thanks,

J1M.

UPDATE1

If I replace this line:

<LinqToXsdBinDir Condition="'$(LinqToXsdBinDir)' == ''">$(SolutionDir)..\LinqToXsd</LinqToXsdBinDir>

With this line:

<LinqToXsdBinDir>$(MSBuildProjectDirectory)\..\LinqToXsd</LinqToXsdBinDir>

In the ConfigTool and BL project files, I no longer get errors about LinqToXsd not being found when it compiles the BL, although it can't find the compiled BL dll.

SOLUTION

First off, SolutionDir is only defined by VS2008, not MSBUILD it seems. You can pass it in on the command line but I chose to do the following:

<LinqToXsdBinDir>$(MSBuildProjectDirectory)\..\LinqToXsd</LinqToXsdBinDir>

MSBuildProjectDirectory is defined in both VS and MSBUILD.

Second, a different problem that caused the same symptoms (don't know why)

One of the projects (BL) referenced a subordinate (SL) and SL's GUID had changed. This didn't matter in VS but MSBUILD really didn't like it.

Deleting and recreating the refs fixed the second solution.

I only found out about it during my random csproj hackings when suddenly MSBUILD started reporting an error about project {guid} referencing project {guid} which is not available in the SLN file

Thanks,

J1M

like image 940
RoboJ1M Avatar asked Nov 29 '25 20:11

RoboJ1M


2 Answers

MSBuild does not define the SolutionDir property so you'll need to manually specify it:

msbuild.exe /p:SolutionDir=... other options
like image 169
Lee Avatar answered Dec 02 '25 10:12

Lee


Nuget works in a similar way. It places it's targets in a subfolder off the solution root. For each project that uses nuget it edits the .*proj file and adds the following SolutionDir property. If you provide a default value for SolutionDir in this manner you shouldn't have to pass it as a command line argument when you invoke msbuild:

  <PropertyGroup>
    <!-- ... other properties -->
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
  </PropertyGroup>

then just update your target like this:

  <Import Project="$(SolutionDir)\LinqToXsd\LinqToXsd.targets" />
like image 39
Jay Walker Avatar answered Dec 02 '25 08:12

Jay Walker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!