$(SolutionDir) is not expanded correctly when referencing projects directly, without going via a solution file

Topics: Developer Forum
Nov 25, 2009 at 4:07 PM
Edited Nov 25, 2009 at 4:28 PM

Hi,

My csprojs are configured as follows

<Project>
  <PropertyGroup>
    <!-- OutputPath is specified in each csproj -->
    <OutputPath>$(SolutionDir)..\build\$(Configuration)\bin\</OutputPath>
    <!-- the following are actually specified in an <Import Project="..\common.targets" /> -->
    <IntermediateOutputPath>$(OutputPath)..\obj\$(MSBuildProjectName)\</IntermediateOutputPath>
    <OutDir>$(OutputPath)</OutDir>
  </PropertyGroup>
</Project>

When specifying my solution file as single DocumentationSource everything works fine, but when I refer to the csprojs directly then I get the following error:

(CoreBuildHelp target) ->
  SHFB : error BE0040: Project assembly does not exist: C:\PATH\TO\SINGLE\CSPROJ\..\build\$(Configuration)\bin\assembly.dll

The shfbproj references the csprojs as follows, but I've confirmed that one single direct reference (with no wildcards) will cause the same problem

<DocumentationSources>
   <DocumentationSource sourceFile="*.csproj" subFolders="True" />
</DocumentationSources>

The directory structure is as follows

 

  • src
    • solution.sln
    • documentation.shfbproj
    • projectA
      • projectA.csproj
    • projectB
      • projectB.csproj
  • build
    • $(Configuration)
      • bin
        • projectA.DLL
        • projectA.xml (the xml doc file)
        • ...
      • obj
        • projectA
        • projectB

 

To me it looks like SHFB is not expanding $(SolutionDir) correctly when expanding OutputPath for the csprojects. Or am I doing something wrong?

Billion thanks in advance for any help!

Coordinator
Nov 25, 2009 at 7:24 PM

Without a solution file, there is no $(SolutionDir) or any of the other related $(Solution*) variables.  It can't guess what they should be set to so they are undefined when it loads an individual project file.  You could try adding a conditional property to the .csproj file that defines $(SolutionDir) if it is undefined.

<Project>
  <PropertyGroup>
    <!-- Define SolutionDir if not already set -->
    <SolutionDir Condition=" '$(SolutionDir)' == '' ">C:\Path\To\Solution\</SolutionDir>

    <!-- OutputPath is specified in each csproj -->
    <OutputPath>$(SolutionDir)..\build\$(Configuration)\bin\</OutputPath>
    <!-- the following are actually specified in an <Import Project="..\common.targets" /> -->
    <IntermediateOutputPath>$(OutputPath)..\obj\$(MSBuildProjectName)\</IntermediateOutputPath>
    <OutDir>$(OutputPath)</OutDir>
  </PropertyGroup>
</Project>

Eric

 

Nov 27, 2009 at 6:27 PM
Edited Nov 27, 2009 at 6:34 PM

Indeed every csproj needs $(SolutionDir) set to something almost at the beginning of the file, as it is used to construct everything else (e.g. $(OutputDir) )

Problem is this means hardcoding a "best guess" path into every csproj, which is not ideal.

Could the SHFB project set $(SolutionDir) when it resolves the assembly paths?

My goal is actually putting the SHFB documentation project in the solution file, so that the developers can build it locally.

Fo that I'd be fine with making the SHFB project point to the solution (=no more $(SolutionDir) problem). But then SHFB will try to extract an assembly name for it and fail EVEN IF I deselect the project in the debug and release configurations of the solution.

So I guess the root problem here is actually that somehow the Visual Studio Configuration Manager settings (i.e. the Build column of tick boxes) are not being honored.

 

I should have said it in my first post...SHFB is great help. Thanks! :-)

 

Coordinator
Nov 28, 2009 at 8:05 PM

> Could the SHFB project set $(SolutionDir) when it resolves the assembly paths?

There in lies the problem.  SHFB doesn't have a $(SolutionDir) to start with so it can't set it to anything.  I suppose I could have it look for it and set that in any projects it opens outside of a solution file if it is defined.  It isn't supported within Visual Studio solution files yet so it's behavior there is not known.  For the time being it would have to be defined manually with the SHFB project.

Eric

 

Nov 28, 2009 at 9:17 PM

are you saying that feature is already available? I mean, do we currently have a way to define $(SolutionDir) manually in the shfbproj once for all the csproj it refers to?

that would definitely be an improvement

Coordinator
Nov 29, 2009 at 1:02 AM

You can add it to the SHFB project but it won't be used in the current release.  I can add support for it to the next release.  You can probably add it using the project's UserDefinedProperties project property since nothing else in the SHFB project will depend on it so it's placement doesn't matter

Eric