@@ -87,7 +87,85 @@ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildInBuildServe
87
87
fileContent . ShouldContain ( @"[assembly: AssemblyVersion(""1.0.1.0"")]" ) ;
88
88
}
89
89
90
- private static void AddUpdateAssemblyInfoTask ( ProjectCreator project , string targetToRun , string taskName , string outputProperty )
90
+ [ Test ]
91
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist ( )
92
+ {
93
+ var task = new UpdateAssemblyInfo { IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
94
+
95
+ using var result = ExecuteMsBuildTask ( task ) ;
96
+
97
+ result . Success . ShouldBe ( true ) ;
98
+ result . Errors . ShouldBe ( 0 ) ;
99
+ result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
100
+
101
+ var fileContent = File . ReadAllText ( result . Task . AssemblyInfoTempFilePath ) ;
102
+ fileContent . ShouldContain ( @"[assembly: AssemblyVersion(""1.2.4.0"")]" ) ;
103
+ }
104
+
105
+ [ Test ]
106
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExistInBuildServer ( )
107
+ {
108
+ var task = new UpdateAssemblyInfo { IntermediateOutputPath = Guid . NewGuid ( ) . ToString ( "N" ) } ;
109
+
110
+ using var result = ExecuteMsBuildTaskInAzurePipeline ( task ) ;
111
+
112
+ result . Success . ShouldBe ( true ) ;
113
+ result . Errors . ShouldBe ( 0 ) ;
114
+ result . Task . AssemblyInfoTempFilePath . ShouldNotBeNull ( ) ;
115
+
116
+ var fileContent = File . ReadAllText ( result . Task . AssemblyInfoTempFilePath ) ;
117
+ fileContent . ShouldContain ( @"[assembly: AssemblyVersion(""1.0.1.0"")]" ) ;
118
+ }
119
+
120
+ [ Test ]
121
+ [ Category ( NoNet48 ) ]
122
+ [ Category ( NoMono ) ]
123
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist ( )
124
+ {
125
+ const string taskName = nameof ( UpdateAssemblyInfo ) ;
126
+ const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
127
+ var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
128
+
129
+ using var result = ExecuteMsBuildExe ( project => AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty , Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ) ) ;
130
+
131
+ result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
132
+ result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
133
+ result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
134
+ result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
135
+ result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
136
+
137
+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , "AssemblyInfo.g.cs" ) ;
138
+ result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
139
+
140
+ var fileContent = File . ReadAllText ( generatedFilePath ) ;
141
+ fileContent . ShouldContain ( @"[assembly: AssemblyVersion(""1.2.4.0"")]" ) ;
142
+ }
143
+
144
+ [ Test ]
145
+ [ Category ( NoNet48 ) ]
146
+ [ Category ( NoMono ) ]
147
+ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer ( )
148
+ {
149
+ const string taskName = nameof ( UpdateAssemblyInfo ) ;
150
+ const string outputProperty = nameof ( UpdateAssemblyInfo . AssemblyInfoTempFilePath ) ;
151
+ var randDir = Guid . NewGuid ( ) . ToString ( "N" ) ;
152
+
153
+ using var result = ExecuteMsBuildExeInAzurePipeline ( project => AddUpdateAssemblyInfoTask ( project , taskName , taskName , outputProperty , Path . Combine ( "$(MSBuildProjectDirectory)" , randDir ) ) ) ;
154
+
155
+ result . ProjectPath . ShouldNotBeNullOrWhiteSpace ( ) ;
156
+ result . MsBuild . Count . ShouldBeGreaterThan ( 0 ) ;
157
+ result . MsBuild . OverallSuccess . ShouldBe ( true ) ;
158
+ result . MsBuild . ShouldAllBe ( x => x . Succeeded ) ;
159
+ result . Output . ShouldNotBeNullOrWhiteSpace ( ) ;
160
+
161
+ var generatedFilePath = PathHelper . Combine ( Path . GetDirectoryName ( result . ProjectPath ) , randDir , "AssemblyInfo.g.cs" ) ;
162
+ result . Output . ShouldContain ( $ "{ outputProperty } : { generatedFilePath } ") ;
163
+
164
+ var fileContent = File . ReadAllText ( generatedFilePath ) ;
165
+ fileContent . ShouldContain ( @"[assembly: AssemblyVersion(""1.0.1.0"")]" ) ;
166
+ }
167
+
168
+ private static void AddUpdateAssemblyInfoTask ( ProjectCreator project , string targetToRun , string taskName , string outputProperty , string intermediateOutputPath = "$(MSBuildProjectDirectory)" )
91
169
{
92
170
var assemblyFileLocation = typeof ( GitVersionTaskBase ) . Assembly . Location ;
93
171
project . UsingTaskAssemblyFile ( taskName , assemblyFileLocation )
@@ -98,7 +176,7 @@ private static void AddUpdateAssemblyInfoTask(ProjectCreator project, string tar
98
176
{ "SolutionDirectory" , "$(MSBuildProjectDirectory)" } ,
99
177
{ "VersionFile" , "$(MSBuildProjectDirectory)/gitversion.json" } ,
100
178
{ "ProjectFile" , "$(MSBuildProjectFullPath)" } ,
101
- { "IntermediateOutputPath" , "$(MSBuildProjectDirectory)" } ,
179
+ { "IntermediateOutputPath" , intermediateOutputPath } ,
102
180
{ "Language" , "$(Language)" } ,
103
181
{ "CompileFiles" , "@(Compile)" }
104
182
} )
0 commit comments