@@ -9,8 +9,9 @@ public class MSBuildProject
99
1010 XmlDocument xd ;
1111
12+ public string ProtoBufTaskPath { get ; private set ; }
1213 public string ProtoGenPath { get ; private set ; }
13- public bool HasProtoGenImport { get ; private set ; }
14+ public bool HasProtoBufTaskImport { get ; private set ; }
1415
1516 public void Open ( string projectFile )
1617 {
@@ -19,13 +20,17 @@ public void Open(string projectFile)
1920
2021 var xnm = new XmlNamespaceManager ( xd . NameTable ) ;
2122 xnm . AddNamespace ( "msbuild" , msbuildNS ) ;
23+ var protoTaskPathNode = xd . SelectSingleNode ( "/msbuild:Project/msbuild:PropertyGroup[not(@Condition)]/msbuild:ProtoBufTaskPath" , xnm ) ;
24+ if ( protoTaskPathNode != null )
25+ ProtoBufTaskPath = protoTaskPathNode . InnerText ;
26+
2227 var protoGenPathNode = xd . SelectSingleNode ( "/msbuild:Project/msbuild:PropertyGroup[not(@Condition)]/msbuild:ProtoGenPath" , xnm ) ;
2328 if ( protoGenPathNode != null )
2429 ProtoGenPath = protoGenPathNode . InnerText ;
2530
26- string importProject = @"$(ProtoGenPath )\ProtoBuf.MSBuildTask.targets" ;
31+ string importProject = @"$(ProtoBufTaskPath )\ProtoBuf.MSBuildTask.targets" ;
2732 var importNode = xd . SelectSingleNode ( "/msbuild:Project/msbuild:Import[@Project='" + importProject + "']" , xnm ) ;
28- HasProtoGenImport = importNode != null ;
33+ HasProtoBufTaskImport = importNode != null ;
2934 }
3035
3136 public string [ ] LoadItems ( )
@@ -37,31 +42,48 @@ public string[] LoadItems()
3742 return nodes . Cast < XmlElement > ( ) . Select ( a => a . GetAttribute ( "Include" ) ) . Where ( a => ! string . IsNullOrEmpty ( a ) ) . ToArray ( ) ;
3843 }
3944
40- public void Init ( string protoGenPath )
45+ public void Init ( string protoBufTaskPath , string protoGenPath )
4146 {
4247 var xnm = new XmlNamespaceManager ( xd . NameTable ) ;
4348 xnm . AddNamespace ( "msbuild" , msbuildNS ) ;
4449
45- string importProject = @"$(ProtoGenPath)\ ProtoBuf.MSBuildTask.targets" ;
50+ string importProject = @"$(ProtoBufTaskPath) ProtoBuf.MSBuildTask.targets" ;
4651 var importNode = xd . SelectSingleNode ( "/msbuild:Project/msbuild:Import[@Project='" + importProject + "']" , xnm ) ;
4752 if ( importNode == null )
4853 {
4954 var xe = xd . CreateElement ( "Import" , msbuildNS ) ;
5055 xe . SetAttribute ( "Project" , importProject ) ;
5156 importNode = xe ;
5257 xd . DocumentElement . AppendChild ( xe ) ;
53- HasProtoGenImport = true ;
58+ HasProtoBufTaskImport = true ;
5459 }
5560
56- var protoGenPathNode = xd . SelectSingleNode ( "/msbuild:Project/msbuild:PropertyGroup[not(@Condition)]/msbuild:ProtoGenPath" , xnm ) ;
57- if ( protoGenPathNode == null )
61+ XmlElement propertyGroupNode ;
62+ var protoBufTaskPathNode = xd . SelectSingleNode ( "/msbuild:Project/msbuild:PropertyGroup[not(@Condition)]/msbuild:ProtoBufTaskPath" , xnm ) ;
63+ if ( protoBufTaskPathNode == null )
5864 {
5965 var xe = xd . CreateElement ( "PropertyGroup" , msbuildNS ) ;
60- var xe2 = xd . CreateElement ( "ProtoGenPath " , msbuildNS ) ;
61- xe2 . InnerText = protoGenPath ;
66+ var xe2 = xd . CreateElement ( "ProtoBufTaskPath " , msbuildNS ) ;
67+ xe2 . InnerText = protoBufTaskPath ;
6268 xe . AppendChild ( xe2 ) ;
69+ propertyGroupNode = xe ;
6370 // ensure properties come before targets
6471 xd . DocumentElement . InsertBefore ( xe , importNode ) ;
72+ ProtoBufTaskPath = protoBufTaskPath ;
73+ }
74+ else
75+ {
76+ propertyGroupNode = protoBufTaskPathNode . ParentNode as XmlElement ;
77+ protoBufTaskPathNode . InnerText = protoBufTaskPath ;
78+ ProtoBufTaskPath = protoBufTaskPath ;
79+ }
80+
81+ var protoGenPathNode = xd . SelectSingleNode ( "/msbuild:Project/msbuild:PropertyGroup[not(@Condition)]/msbuild:ProtoGenPath" , xnm ) ;
82+ if ( protoGenPathNode == null )
83+ {
84+ var xe2 = xd . CreateElement ( "ProtoGenPath" , msbuildNS ) ;
85+ xe2 . InnerText = protoGenPath ;
86+ propertyGroupNode . AppendChild ( xe2 ) ;
6587 ProtoGenPath = protoGenPath ;
6688 }
6789 else
0 commit comments