@@ -29,7 +29,7 @@ namespace ICSharpCode.Decompiler.Solution
29
29
/// </summary>
30
30
public static class SolutionCreator
31
31
{
32
- static readonly XNamespace ProjectFileNamespace = XNamespace . Get ( "http://schemas.microsoft.com/developer/msbuild/2003" ) ;
32
+ static readonly XNamespace NonSDKProjectFileNamespace = XNamespace . Get ( "http://schemas.microsoft.com/developer/msbuild/2003" ) ;
33
33
34
34
/// <summary>
35
35
/// Writes a solution file to the specified <paramref name="targetFile"/>.
@@ -63,7 +63,7 @@ public static void WriteSolutionFile(string targetFile, List<ProjectItem> projec
63
63
WriteSolutionFile ( writer , projects , targetFile ) ;
64
64
}
65
65
66
- FixProjectReferences ( projects ) ;
66
+ FixAllProjectReferences ( projects ) ;
67
67
}
68
68
69
69
static void WriteSolutionFile ( TextWriter writer , List < ProjectItem > projects , string solutionFilePath )
@@ -153,7 +153,7 @@ static void WriteProjectConfigurations(
153
153
writer . WriteLine ( "\t EndGlobalSection" ) ;
154
154
}
155
155
156
- static void FixProjectReferences ( List < ProjectItem > projects )
156
+ static void FixAllProjectReferences ( List < ProjectItem > projects )
157
157
{
158
158
var projectsMap = projects . ToDictionary (
159
159
p => p . ProjectName ,
@@ -170,9 +170,11 @@ static void FixProjectReferences(List<ProjectItem> projects)
170
170
$ "no <Project> at the root; could not fix project references.") ;
171
171
}
172
172
173
+ // sdk style projects don't use a namespace for the elements,
174
+ // but we still need to use the namespace for non-sdk style projects.
173
175
var sdkStyle = projectDoc . Root . Attribute ( "Sdk" ) != null ;
174
- var itemGroupTagName = sdkStyle ? "ItemGroup" : ProjectFileNamespace + "ItemGroup" ;
175
- var referenceTagName = sdkStyle ? "Reference" : ProjectFileNamespace + "Reference" ;
176
+ var itemGroupTagName = sdkStyle ? "ItemGroup" : NonSDKProjectFileNamespace + "ItemGroup" ;
177
+ var referenceTagName = sdkStyle ? "Reference" : NonSDKProjectFileNamespace + "Reference" ;
176
178
177
179
var referencesItemGroups = projectDoc . Root
178
180
. Elements ( itemGroupTagName )
@@ -191,12 +193,11 @@ static void FixProjectReferences(List<ProjectItem> projects)
191
193
static void FixProjectReferences ( string projectFilePath , XElement itemGroup ,
192
194
Dictionary < string , ProjectItem > projects , bool sdkStyle )
193
195
{
194
- XName GetElementName ( string localName ) => sdkStyle ? localName : ProjectFileNamespace + localName ;
196
+
197
+ XName GetElementName ( string name ) => sdkStyle ? name : NonSDKProjectFileNamespace + name ;
195
198
196
199
var referenceTagName = GetElementName ( "Reference" ) ;
197
200
var projectReferenceTagName = GetElementName ( "ProjectReference" ) ;
198
- var projectTagName = GetElementName ( "Project" ) ;
199
- var nameTagName = GetElementName ( "Name" ) ;
200
201
201
202
foreach ( var item in itemGroup . Elements ( referenceTagName ) . ToList ( ) )
202
203
{
@@ -205,10 +206,20 @@ static void FixProjectReferences(string projectFilePath, XElement itemGroup,
205
206
{
206
207
item . Remove ( ) ;
207
208
208
- var projectReference = new XElement ( projectReferenceTagName ,
209
- new XElement ( projectTagName , referencedProject . Guid . ToString ( "B" ) . ToLowerInvariant ( ) ) ,
210
- new XElement ( nameTagName , referencedProject . ProjectName ) ) ;
211
- projectReference . SetAttributeValue ( "Include" , GetRelativePath ( projectFilePath , referencedProject . FilePath ) ) ;
209
+ var projectReference = new XElement (
210
+ projectReferenceTagName ,
211
+ new XAttribute ( "Include" , GetRelativePath ( projectFilePath , referencedProject . FilePath ) ) ) ;
212
+
213
+ // SDK-style projects do not use the <Project> and <Name> elements for project references.
214
+ // (Instead, those get read from the .csproj file in "Include".)
215
+ if ( ! sdkStyle )
216
+ {
217
+ projectReference . Add (
218
+ // no ToUpper() for uuids, most Microsoft tools seem to emit them in lowercase
219
+ // (no .ToLower() as .ToString("B") already outputs lowercase)
220
+ new XElement ( NonSDKProjectFileNamespace + "Project" , referencedProject . Guid . ToString ( "B" ) ) ,
221
+ new XElement ( NonSDKProjectFileNamespace + "Name" , referencedProject . ProjectName ) ) ;
222
+ }
212
223
213
224
itemGroup . Add ( projectReference ) ;
214
225
}
0 commit comments