@@ -104,7 +104,101 @@ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildI
104
104
fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.0.1+1""") ;
105
105
}
106
106
107
- private static void AddGenerateGitVersionInformationTask ( ProjectCreator project , string targetToRun , string taskName , string outputProperty )
107
+ [ Test ]
108
+ public void GenerateGitVersionInformationTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist ( )
109
+ {
110
+ var task = new GenerateGitVersionInformation { IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
111
+
112
+ using var result = ExecuteMsBuildTask ( task ) ;
113
+
114
+ result . Success . ShouldBe ( true ) ;
115
+ result . Errors . ShouldBe ( 0 ) ;
116
+ result . Task . GitVersionInformationFilePath . ShouldNotBeNull ( ) ;
117
+
118
+ var fileContent = File . ReadAllText ( result . Task . GitVersionInformationFilePath ) ;
119
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Major ) } = ""1""") ;
120
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Minor ) } = ""2""") ;
121
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Patch ) } = ""4""") ;
122
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . MajorMinorPatch ) } = ""1.2.4""") ;
123
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.2.4+1""") ;
124
+ }
125
+
126
+ [ Test ]
127
+ public void GenerateGitVersionInformationTaskShouldCreateFileInBuildServerWhenIntermediateOutputPathDoesNotExist ( )
128
+ {
129
+ var task = new GenerateGitVersionInformation { IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
130
+
131
+ using var result = ExecuteMsBuildTaskInAzurePipeline ( task ) ;
132
+
133
+ result . Success . ShouldBe ( true ) ;
134
+ result . Errors . ShouldBe ( 0 ) ;
135
+ result . Task . GitVersionInformationFilePath . ShouldNotBeNull ( ) ;
136
+
137
+ var fileContent = File . ReadAllText ( result . Task . GitVersionInformationFilePath ) ;
138
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Major ) } = ""1""") ;
139
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Minor ) } = ""0""") ;
140
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Patch ) } = ""1""") ;
141
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . MajorMinorPatch ) } = ""1.0.1""") ;
142
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.0.1+1""") ;
143
+ }
144
+
145
+ [ Test ]
146
+ [ Category ( NoNet48 ) ]
147
+ [ Category ( NoMono ) ]
148
+ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist ( )
149
+ {
150
+ const string taskName = nameof ( GenerateGitVersionInformation ) ;
151
+ const string outputProperty = nameof ( GenerateGitVersionInformation . GitVersionInformationFilePath ) ;
152
+ var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
153
+
154
+ using var result = ExecuteMsBuildExe ( project => AddGenerateGitVersionInformationTask ( project , taskName , taskName , outputProperty , Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ) ) ;
155
+
156
+ result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
157
+ result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
158
+ result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
159
+ result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
160
+ result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
161
+
162
+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , "GitVersionInformation.g.cs" ) ;
163
+ result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
164
+
165
+ var fileContent = File . ReadAllText ( generatedFilePath ) ;
166
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Major ) } = ""1""") ;
167
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Minor ) } = ""2""") ;
168
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Patch ) } = ""4""") ;
169
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . MajorMinorPatch ) } = ""1.2.4""") ;
170
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.2.4+1""") ;
171
+ }
172
+
173
+ [ Test ]
174
+ [ Category ( NoNet48 ) ]
175
+ [ Category ( NoMono ) ]
176
+ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer ( )
177
+ {
178
+ const string taskName = nameof ( GenerateGitVersionInformation ) ;
179
+ const string outputProperty = nameof ( GenerateGitVersionInformation . GitVersionInformationFilePath ) ;
180
+ var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
181
+
182
+ using var result = ExecuteMsBuildExeInAzurePipeline ( project => AddGenerateGitVersionInformationTask ( project , taskName , taskName , outputProperty , Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ) ) ;
183
+
184
+ result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
185
+ result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
186
+ result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
187
+ result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
188
+ result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
189
+
190
+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , "GitVersionInformation.g.cs" ) ;
191
+ result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
192
+
193
+ var fileContent = File . ReadAllText ( generatedFilePath ) ;
194
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Major ) } = ""1""") ;
195
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Minor ) } = ""0""") ;
196
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . Patch ) } = ""1""") ;
197
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . MajorMinorPatch ) } = ""1.0.1""") ;
198
+ fileContent . ShouldContain ( $@ "{ nameof ( VersionVariables . FullSemVer ) } = ""1.0.1+1""") ;
199
+ }
200
+
201
+ private static void AddGenerateGitVersionInformationTask ( ProjectCreator project , string targetToRun , string taskName , string outputProperty , string intermediateOutputPath = "$(MSBuildProjectDirectory)" )
108
202
{
109
203
var assemblyFileLocation = typeof ( GitVersionTaskBase ) . Assembly . Location ;
110
204
project . UsingTaskAssemblyFile ( taskName , assemblyFileLocation )
@@ -115,7 +209,7 @@ private static void AddGenerateGitVersionInformationTask(ProjectCreator project,
115
209
{ "SolutionDirectory" , "$(MSBuildProjectDirectory)" } ,
116
210
{ "VersionFile" , "$(MSBuildProjectDirectory)/gitversion.json" } ,
117
211
{ "ProjectFile" , "$(MSBuildProjectFullPath)" } ,
118
- { "IntermediateOutputPath" , "$(MSBuildProjectDirectory)" } ,
212
+ { "IntermediateOutputPath" , intermediateOutputPath } ,
119
213
{ "Language" , "$(Language)" }
120
214
} )
121
215
. TaskOutputProperty ( outputProperty , outputProperty )
0 commit comments