Skip to content

Commit

Permalink
Check FullPath for versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed Mar 27, 2024
1 parent 5b6e1dc commit bd8ed85
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions src/IKVM.Core.MSBuild.Tasks/GenerateDepsFileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ RuntimeAssetGroup BuildRuntimeLibraryRuntimeAssemblyGroupWithAdditional(Dependen
runtimeFiles.Remove(file);

var assemblyVersion = addl.GetMetadata(METADATA_LIBRARY_ASSET_ASSEMBLYVERSION) ?? file?.AssemblyVersion;
if (string.IsNullOrEmpty(assemblyVersion) && File.Exists(addl.ItemSpec))
if (TryLoadAssemblyVersion(addl.ItemSpec, out var v))
if (string.IsNullOrEmpty(assemblyVersion))
if (TryLoadAssemblyVersion(addl, out var v))
assemblyVersion = v;

var fileVersion = addl.GetMetadata(METADATA_LIBRARY_ASSET_FILEVERSION) ?? file?.FileVersion;
if (string.IsNullOrEmpty(fileVersion) && File.Exists(addl.ItemSpec))
if (TryLoadFileVersion(addl.ItemSpec, out var v))
if (string.IsNullOrEmpty(fileVersion))
if (TryLoadFileVersion(addl, out var v))
fileVersion = v;

runtimeFiles.Add(new RuntimeFile(path, assemblyVersion, fileVersion));
Expand Down Expand Up @@ -242,13 +242,13 @@ RuntimeAssetGroup BuildRuntimeLibraryNativeAssetGroupWithAdditional(DependencyCo
runtimeFiles.Remove(file);

var assemblyVersion = addl.GetMetadata(METADATA_LIBRARY_ASSET_ASSEMBLYVERSION) ?? file?.AssemblyVersion;
if (string.IsNullOrEmpty(assemblyVersion) && File.Exists(addl.ItemSpec))
if (TryLoadAssemblyVersion(addl.ItemSpec, out var v))
if (string.IsNullOrEmpty(assemblyVersion))
if (TryLoadAssemblyVersion(addl, out var v))
assemblyVersion = v;

var fileVersion = addl.GetMetadata(METADATA_LIBRARY_ASSET_FILEVERSION) ?? file?.FileVersion;
if (string.IsNullOrEmpty(fileVersion) && File.Exists(addl.ItemSpec))
if (TryLoadFileVersion(addl.ItemSpec, out var v))
if (string.IsNullOrEmpty(fileVersion))
if (TryLoadFileVersion(addl, out var v))
fileVersion = v;

runtimeFiles.Add(new RuntimeFile(path, assemblyVersion, fileVersion));
Expand All @@ -257,6 +257,24 @@ RuntimeAssetGroup BuildRuntimeLibraryNativeAssetGroupWithAdditional(DependencyCo
return new RuntimeAssetGroup(runtime, runtimeFiles);
}

/// <summary>
/// Attempts to get the assembly version of an item.
/// </summary>
/// <param name="item"></param>
/// <param name="assemblyVersion"></param>
/// <returns></returns>
bool TryLoadAssemblyVersion(ITaskItem item, out string assemblyVersion)
{
if (File.Exists(item.ItemSpec))
return TryLoadAssemblyVersion(item.ItemSpec, out assemblyVersion);

if (item.GetMetadata("FullPath") is string fullPath && File.Exists(fullPath))
return TryLoadAssemblyVersion(fullPath, out assemblyVersion);

assemblyVersion = null;
return false;
}

/// <summary>
/// Attempts to get the assembly version of a file.
/// </summary>
Expand All @@ -277,6 +295,25 @@ bool TryLoadAssemblyVersion(string path, out string assemblyVersion)
}
}


/// <summary>
/// Attempts to get the file version of an item.
/// </summary>
/// <param name="item"></param>
/// <param name="assemblyVersion"></param>
/// <returns></returns>
bool TryLoadFileVersion(ITaskItem item, out string fileVersion)
{
if (File.Exists(item.ItemSpec))
return TryLoadFileVersion(item.ItemSpec, out fileVersion);

if (item.GetMetadata("FullPath") is string fullPath && File.Exists(fullPath))
return TryLoadFileVersion(fullPath, out fileVersion);

fileVersion = null;
return false;
}

/// <summary>
/// Tries to load the file version of a file.
/// </summary>
Expand Down

0 comments on commit bd8ed85

Please sign in to comment.