Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Handle unix slashes in project file paths in a .sln file
Browse files Browse the repository at this point in the history
Given a .sln with:

Projects A, B and C.
A has a ProjectReference to B
B depends on C, specified in the .sln file

```
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibB", "LibB\LibB.csproj", "{34ED4F6B-145E-467E-AFFB-48B3237878D3}"
        ProjectSection(ProjectDependencies) = postProject
                        {9C743F94-9DA8-422B-8FB8-DEB139216381} = {9C743F94-9DA8-422B-8FB8-DEB139216381}
        EndProjectSection
EndProject
```

Building this with msbuild:

```
"/Users/ankit/Projects/SlnProjectDepsBug/SlnProjectDepsBug.sln" (default target) (1) ->
"/Users/ankit/Projects/SlnProjectDepsBug/LibB/LibB.csproj.metaproj" (default target) (5) ->
  /Users/ankit/Projects/SlnProjectDepsBug/LibB/LibB.csproj.metaproj : error MSB4025: The project file could not be loaded. Could not find file "/Users/ankit/Projects/SlnProjectDepsBug/LibB/LibB.csproj.metaproj".
```

The solution project generator creates a Project and ProjectInstance for
`LibB.csproj.metaproj`, and a `BuildRequestConfiguration` gets added to
`BuilderManager._configCache` from `LoadSolutionIntoConfiguration`. But it has
a property:

	CurrentSolutionConfigurationContents=<SolutionConfiguration>
		<ProjectConfiguration Project="{2A45AC7E-98A0-4AA8-84F0-7C02A7469313}" AbsolutePath="/Users/ankit/Projects/SlnProjectDepsBug/SlnProjectDepsBug\SlnProjectDepsBug.csproj" BuildProjectInSolution="True">Debug|x86</ProjectConfiguration>
		  <ProjectConfiguration Project="{9C743F94-9DA8-422B-8FB8-DEB139216381}" AbsolutePath="/Users/ankit/Projects/SlnProjectDepsBug/LibC\LibC.csproj" BuildProjectInSolution="True">Debug|AnyCPU</ProjectConfiguration>
		  <ProjectConfiguration Project="{34ED4F6B-145E-467E-AFFB-48B3237878D3}" AbsolutePath="/Users/ankit/Projects/SlnProjectDepsBug/LibB\LibB.csproj" BuildProjectInSolution="True">Debug|AnyCPU<ProjectDependency Project="{9C743F94-9DA8-422B-8FB8-DEB139216381}" /></ProjectConfiguration>
		</SolutionConfiguration>

.. with `LibB\LibB.csproj`.

And at a later point the instance gets looked up from
`BuildRequestEngine.IssueBuildRequests`, and at this point the build
request has the same property but with fixed paths, which causes the
`GetMatchingConfiguration` to fail trying to match the property. IOW, it
fails to find the `ProjectInstance` for `LibB.csproj.metaproj` and so tries
to load the project file instead, which doesn't exist on disk!

`ProjectInSolution.RelativePath` should fix up the project path being read from
the sln file. `ParentSolution.SolutionFileDirectory` is built correctly,
and it's setter is used only by tests. So `ProjectInSolution.AbsolutePath`
doesn't need to be updated.

FIXME: Added a test project but it is not integrated in the build. It
should probably be added in SolutionProjectGenerator_Tests.

(dotnet#1957)
  • Loading branch information
Ankit Jain committed May 3, 2017
1 parent 3985d1b commit 86adc96
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 1 deletion.
37 changes: 37 additions & 0 deletions mono/tests/SlnProjectDepsBug/LibB/LibB.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{34ED4F6B-145E-467E-AFFB-48B3237878D3}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>LibB</RootNamespace>
<AssemblyName>LibB</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
10 changes: 10 additions & 0 deletions mono/tests/SlnProjectDepsBug/LibB/MyClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
namespace LibB
{
public class MyClass
{
public MyClass()
{
}
}
}
26 changes: 26 additions & 0 deletions mono/tests/SlnProjectDepsBug/LibB/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("LibB")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("${AuthorCopyright}")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
37 changes: 37 additions & 0 deletions mono/tests/SlnProjectDepsBug/LibC/LibC.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9C743F94-9DA8-422B-8FB8-DEB139216381}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>LibC</RootNamespace>
<AssemblyName>LibC</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
10 changes: 10 additions & 0 deletions mono/tests/SlnProjectDepsBug/LibC/MyClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
namespace LibC
{
public class MyClass
{
public MyClass()
{
}
}
}
26 changes: 26 additions & 0 deletions mono/tests/SlnProjectDepsBug/LibC/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("LibC")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("${AuthorCopyright}")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
32 changes: 32 additions & 0 deletions mono/tests/SlnProjectDepsBug/SlnProjectDepsBug.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnProjectDepsBug", "SlnProjectDepsBug\SlnProjectDepsBug.csproj", "{2A45AC7E-98A0-4AA8-84F0-7C02A7469313}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibC", "LibC\LibC.csproj", "{9C743F94-9DA8-422B-8FB8-DEB139216381}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibB", "LibB\LibB.csproj", "{34ED4F6B-145E-467E-AFFB-48B3237878D3}"
ProjectSection(ProjectDependencies) = postProject
{9C743F94-9DA8-422B-8FB8-DEB139216381} = {9C743F94-9DA8-422B-8FB8-DEB139216381}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2A45AC7E-98A0-4AA8-84F0-7C02A7469313}.Debug|x86.ActiveCfg = Debug|x86
{2A45AC7E-98A0-4AA8-84F0-7C02A7469313}.Debug|x86.Build.0 = Debug|x86
{2A45AC7E-98A0-4AA8-84F0-7C02A7469313}.Release|x86.ActiveCfg = Release|x86
{2A45AC7E-98A0-4AA8-84F0-7C02A7469313}.Release|x86.Build.0 = Release|x86
{9C743F94-9DA8-422B-8FB8-DEB139216381}.Debug|x86.ActiveCfg = Debug|Any CPU
{9C743F94-9DA8-422B-8FB8-DEB139216381}.Debug|x86.Build.0 = Debug|Any CPU
{9C743F94-9DA8-422B-8FB8-DEB139216381}.Release|x86.ActiveCfg = Release|Any CPU
{9C743F94-9DA8-422B-8FB8-DEB139216381}.Release|x86.Build.0 = Release|Any CPU
{34ED4F6B-145E-467E-AFFB-48B3237878D3}.Debug|x86.ActiveCfg = Debug|Any CPU
{34ED4F6B-145E-467E-AFFB-48B3237878D3}.Debug|x86.Build.0 = Debug|Any CPU
{34ED4F6B-145E-467E-AFFB-48B3237878D3}.Release|x86.ActiveCfg = Release|Any CPU
{34ED4F6B-145E-467E-AFFB-48B3237878D3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions mono/tests/SlnProjectDepsBug/SlnProjectDepsBug/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace SlnProjectDepsBug
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("SlnProjectDepsBug")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("${AuthorCopyright}")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{2A45AC7E-98A0-4AA8-84F0-7C02A7469313}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>SlnProjectDepsBug</RootNamespace>
<AssemblyName>SlnProjectDepsBug</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibB\LibB.csproj">
<Project>{34ED4F6B-145E-467E-AFFB-48B3237878D3}</Project>
<Name>LibB</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
7 changes: 6 additions & 1 deletion src/Build/Construction/Solution/ProjectInSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Security;
using System.Text;
using System.Xml;
using Microsoft.Build.Shared;

using XMakeAttributes = Microsoft.Build.Shared.XMakeAttributes;
using ProjectFileErrorUtilities = Microsoft.Build.Shared.ProjectFileErrorUtilities;
Expand Down Expand Up @@ -154,7 +155,11 @@ public string ProjectName
public string RelativePath
{
get { return _relativePath; }
internal set { _relativePath = value; }
internal set
{
_relativePath = FileUtilities.MaybeAdjustFilePath(value,
baseDirectory:this.ParentSolution.SolutionFileDirectory ?? String.Empty);
}
}

/// <summary>
Expand Down

0 comments on commit 86adc96

Please sign in to comment.