@@ -13,9 +13,6 @@ namespace Microsoft.Build.Tasks.Git
1313{
1414 public abstract class RepositoryTask : Task
1515 {
16- // Include the assembly version in the key to avoid conflicts with other SourceLink versions.
17- private static readonly string s_cacheKeyPrefix = $ "3AE29AB7-AE6B-48BA-9851-98A15ED51C94:{ typeof ( RepositoryTask ) . Assembly . GetName ( ) . Version } :";
18-
1916 /// <summary>
2017 /// Sets the scope of git repository configuration. By default (no scope specified) configuration is read from environment variables
2118 /// and system and global user git/ssh configuration files.
@@ -142,38 +139,34 @@ private void ExecuteImpl()
142139 return repository ;
143140 }
144141
145- private string GetCacheKey ( string repositoryId )
146- => s_cacheKeyPrefix + ( string . IsNullOrEmpty ( ConfigurationScope ) ? "*" : ConfigurationScope ) + ":" + repositoryId ;
142+ private Tuple < Type , string > GetCacheKey ( string repositoryId )
143+ => new ( typeof ( RepositoryTask ) , ( string . IsNullOrEmpty ( ConfigurationScope ) ? "*" : ConfigurationScope ) + ":" + repositoryId ) ;
147144
148- private bool TryGetCachedRepositoryInstance ( string cacheKey , bool requireCached , [ NotNullWhen ( true ) ] out GitRepository ? repository )
145+ private bool TryGetCachedRepositoryInstance ( Tuple < Type , string > cacheKey , bool requireCached , [ NotNullWhen ( true ) ] out GitRepository ? repository )
149146 {
150- StrongBox < GitRepository ? > ? entry ;
151- try
152- {
153- entry = ( StrongBox < GitRepository ? > ? ) BuildEngine4 . GetRegisteredTaskObject ( cacheKey , RegisteredTaskObjectLifetime . Build ) ;
154- }
155- catch ( InvalidCastException ) // workaround for https://github.com/dotnet/msbuild/issues/8478
156- {
157- entry = null ;
158- }
159-
147+ var entry = ( StrongBox < GitRepository ? > ? ) BuildEngine4 . GetRegisteredTaskObject ( cacheKey , RegisteredTaskObjectLifetime . Build ) ;
160148 if ( entry != null )
161149 {
162150 Log . LogMessage ( MessageImportance . Low , $ "SourceLink: Reusing cached git repository information.") ;
163151 repository = entry . Value ;
164152 return repository != null ;
165153 }
166154
155+ var message = $ "SourceLink: Repository instance not found in cache: '{ cacheKey . Item2 } '";
167156 if ( requireCached )
168157 {
169- Log . LogError ( $ "SourceLink: Repository instance not found in cache: '{ cacheKey . Substring ( s_cacheKeyPrefix . Length ) } '") ;
158+ Log . LogError ( message ) ;
159+ }
160+ else
161+ {
162+ Log . LogMessage ( MessageImportance . Low , message ) ;
170163 }
171164
172165 repository = null ;
173166 return false ;
174167 }
175168
176- private void CacheRepositoryInstance ( string cacheKey , GitRepository ? repository )
169+ private void CacheRepositoryInstance ( Tuple < Type , string > cacheKey , GitRepository ? repository )
177170 {
178171 BuildEngine4 . RegisterTaskObject (
179172 cacheKey ,
0 commit comments