Skip to content

Commit

Permalink
fix: support projects without assemblyname
Browse files Browse the repository at this point in the history
  • Loading branch information
nevse committed Sep 9, 2023
1 parent 7933e1d commit d104965
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions ConvA/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,6 @@ static async Task SaveConfig(string repoPath, ConversionType? conversionType, st
var config = new Config { RepositoryPath = repoPath, ConversionType = conversionType };
await using var configStream = configFileInfo.OpenWrite();
await JsonSerializer.SerializeAsync(configStream, config, SourceGenerationContext.Default.Config);
await configStream.FlushAsync();
}
}
7 changes: 5 additions & 2 deletions ConvA/RepoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ public void Build() {
DevExpressDataVersion = project.EvaluateProperty("DevExpress_Data");
}
string? assemblyName = project.EvaluateProperty("AssemblyName");
if (Path.GetFileNameWithoutExtension(projectPath.FullName) != assemblyName)
string assemblyNameFromProject = Path.GetFileNameWithoutExtension(projectPath.FullName);
if (String.IsNullOrEmpty(assemblyName))
Console.WriteLine($"Can't find assemblyName, suppose it as {assemblyNameFromProject} from project name.");
if (!String.IsNullOrEmpty(assemblyName) && assemblyNameFromProject != assemblyName)
continue;
ProjectsByNameDictionary.Add(assemblyName, projectPath.FullName);
ProjectsByNameDictionary.Add(assemblyNameFromProject, projectPath.FullName);
}
}

Expand Down
22 changes: 15 additions & 7 deletions ConvA/Workspace/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public override string ToString() {
}

public string? EvaluateProperty(string name, string? defaultValue = null) {
if (name == "MSBuildThisFileDirectory")
return MSPath.GetDirectoryName(ProjectPath);
MatchCollection? propertyMatches = GetPropertyMatches(ProjectPath, name);
if (propertyMatches == null)
return defaultValue;
Expand Down Expand Up @@ -150,10 +152,10 @@ public void RemoveAsset(string asset) {
string? include = node.Attributes?["Include"]?.Value;
if (include is null)
continue;
string absIncludePath = Path.IsPathRooted(include) ? include : Path.GetFullPath(ProjectDirectory, include);
string relativePath = Path.GetRelativePath(ProjectDirectory, absIncludePath);
string commonPath = PathHelper.GetCommonPath(relativePath, asset);
if (String.IsNullOrEmpty(commonPath))
string absIncludePath = Path.IsPathRooted(include) ? include : Path.GetFullPath(include, ProjectDirectory).ToPlatformPath();
string relativePath = Path.GetRelativePath(ProjectDirectory, absIncludePath).ToPlatformPath();
string commonPath = PathHelper.GetCommonPath(relativePath, asset).ToPlatformPath();
if (String.IsNullOrEmpty(commonPath.Trim('*')))
continue;
if (PathHelper.HasCommonPath(commonPath, asset)) {
node.ParentNode?.RemoveChild(node);
Expand All @@ -169,7 +171,7 @@ public void AddOrUpdateAsset(string asset) {
string? include = node.Attributes?["Include"]?.Value;
if (include is null)
continue;
string absIncludePath = Path.IsPathRooted(include) ? include : Path.GetFullPath(ProjectDirectory, include);
string absIncludePath = Path.IsPathRooted(include) ? include : Path.GetFullPath(include, ProjectDirectory);
string relativePath = Path.GetRelativePath(ProjectDirectory, absIncludePath);
string commonPath = PathHelper.GetCommonPath(relativePath, asset);
if (String.IsNullOrEmpty(commonPath))
Expand Down Expand Up @@ -526,8 +528,13 @@ XmlNode GetItemGroupWithPackageReferences() {

return GetPropertyMatches(propsFile, propertyName, true);
}

private string? GetDirectoryPropsPath(string? workspacePath) {
string ExpandPathWithProjectVariables(string path) {
string result = path;
if (path.Contains("$(MSBuildThisFileDirectory)"))
result = path.Replace("$(MSBuildThisFileDirectory)", MSPath.GetDirectoryName(ProjectPath) ?? throw new InvalidOperationException());
return result;
}
string? GetDirectoryPropsPath(string? workspacePath) {
if (workspacePath != null) {
string[] propFiles = Directory.GetFiles(workspacePath, "Directory.Build.props", SearchOption.TopDirectoryOnly);
if (propFiles.Length > 0)
Expand Down Expand Up @@ -620,6 +627,7 @@ public List<ProjectReference> GetProjectReferences() {
string? include = projectReferenceNode.Attributes?["Include"]?.Value;
if (include == null)
continue;
include = ExpandPathWithProjectVariables(include);
string? condition = projectReferenceNode.ParentNode?.Attributes?["Condition"]?.Value;
if (!Path.IsPathRooted(include))
include = Path.GetFullPath(ProjectDirectory, include);
Expand Down

0 comments on commit d104965

Please sign in to comment.