Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove redundant properties in ProjectFactory #6192

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 23 additions & 31 deletions src/NuGet.Clients/NuGet.CommandLine/Commands/ProjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void Initialize(dynamic project)
string targetFrameworkMoniker = _project.GetPropertyValue("TargetFrameworkMoniker");
if (!string.IsNullOrEmpty(targetFrameworkMoniker))
{
TargetFramework = NuGetFramework.Parse(targetFrameworkMoniker);
_targetFramework = NuGetFramework.Parse(targetFrameworkMoniker);
}

// This happens before we obtain warning properties, so this Logger is still IConsole.
Expand Down Expand Up @@ -173,17 +173,9 @@ public WarningProperties GetWarningPropertiesForProject()
warningsNotAsErrors: GetPropertyValue("WarningsNotAsErrors"));
}

private string TargetPath
{
get;
set;
}
private string _targetPath;

private NuGetFramework TargetFramework
{
get;
set;
}
private NuGetFramework _targetFramework;

public void SetIncludeSymbols(bool includeSymbols)
{
Expand Down Expand Up @@ -230,12 +222,12 @@ public PackageBuilder CreateBuilder(string basePath, NuGetVersion version, strin
BuildProject();
}

if (!string.IsNullOrEmpty(TargetPath))
if (!string.IsNullOrEmpty(_targetPath))
{
Logger.Log(PackagingLogMessage.CreateMessage(string.Format(
CultureInfo.CurrentCulture,
LocalizedResourceManager.GetString("PackagingFilesFromOutputPath"),
Path.GetFullPath(Path.GetDirectoryName(TargetPath))), LogLevel.Minimal));
Path.GetFullPath(Path.GetDirectoryName(_targetPath))), LogLevel.Minimal));
}

string usingNETSDK = _project.GetPropertyValue("UsingMicrosoftNETSDK");
Expand Down Expand Up @@ -267,7 +259,7 @@ public PackageBuilder CreateBuilder(string basePath, NuGetVersion version, strin
Logger.Log(PackagingLogMessage.CreateError(string.Format(
CultureInfo.CurrentCulture,
LocalizedResourceManager.GetString("UnableToExtractAssemblyMetadata"),
Path.GetFileName(TargetPath)), NuGetLogCode.NU5011));
Path.GetFileName(_targetPath)), NuGetLogCode.NU5011));
if (LogLevel == LogLevel.Verbose)
{
Logger.Log(PackagingLogMessage.CreateError(ex.ToString(), NuGetLogCode.NU5011));
Expand Down Expand Up @@ -455,25 +447,25 @@ private void BuildProject()
{
if (Build)
{
if (TargetFramework != null)
if (_targetFramework != null)
{
Logger.Log(PackagingLogMessage.CreateMessage(string.Format(
CultureInfo.CurrentCulture,
LocalizedResourceManager.GetString("BuildingProjectTargetingFramework"),
_project.FullPath,
TargetFramework), LogLevel.Minimal));
_targetFramework), LogLevel.Minimal));
}

BuildProjectWithMsbuild();
}
else
{
TargetPath = ResolveTargetPath();
_targetPath = ResolveTargetPath();

// Make if the target path doesn't exist, fail
if (!Directory.Exists(TargetPath) && !File.Exists(TargetPath))
if (!Directory.Exists(_targetPath) && !File.Exists(_targetPath))
{
throw new PackagingException(NuGetLogCode.NU5012, string.Format(CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("UnableToFindBuildOutput"), TargetPath));
throw new PackagingException(NuGetLogCode.NU5012, string.Format(CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("UnableToFindBuildOutput"), _targetPath));
}
}
}
Expand All @@ -496,7 +488,7 @@ private void BuildProjectWithMsbuild()
throw new PackagingException(NuGetLogCode.NU5013, error);
}

TargetPath = ResolveTargetPath();
_targetPath = ResolveTargetPath();
}

private string ResolveTargetPath()
Expand Down Expand Up @@ -636,7 +628,7 @@ private void RecursivelyApply(Action<ProjectFactory> action, dynamic alreadyAppl
referencedProject.Build = Build;
referencedProject.IncludeReferencedProjects = IncludeReferencedProjects;
referencedProject.ProjectProperties = ProjectProperties;
referencedProject.TargetFramework = TargetFramework;
referencedProject._targetFramework = _targetFramework;
referencedProject.BuildProject();
referencedProject.SymbolPackageFormat = SymbolPackageFormat;
referencedProject.RecursivelyApply(action, alreadyAppliedProjects);
Expand Down Expand Up @@ -810,14 +802,14 @@ private void ExtractMetadata(Packaging.PackageBuilder builder)
// If building an xproj, then TargetPath points to the folder where the framework folders will be
// instead of to a single dll. Skip trying to ExtractMetadata from the dll and instead
// use only metadata from the project and json file.
if (!Directory.Exists(TargetPath))
if (!Directory.Exists(_targetPath))
{
// If building a project targeting netstandard, asssembly metadata extraction fails
// because it tries to load system.runtime version 4.1.0 which is not present in the local
// path or the gac. In this case, we should just skip it and extract metadata from the project.
try
{
new AssemblyMetadataExtractor(Logger).ExtractMetadata(builder, TargetPath);
new AssemblyMetadataExtractor(Logger).ExtractMetadata(builder, _targetPath);
}
catch (PackagingException packex) when (packex.AsLogMessage().Code.Equals(NuGetLogCode.NU5133))
{
Expand Down Expand Up @@ -853,19 +845,19 @@ private void AddOutputFiles(Packaging.PackageBuilder builder)
}
else
{
nugetFramework = TargetFramework;
nugetFramework = _targetFramework;
}

var projectOutputDirectory = Path.GetDirectoryName(TargetPath);
var projectOutputDirectory = Path.GetDirectoryName(_targetPath);
string targetFileName;

if (Directory.Exists(TargetPath))
if (Directory.Exists(_targetPath))
{
targetFileName = builder.Id;
}
else
{
targetFileName = Path.GetFileNameWithoutExtension(TargetPath);
targetFileName = Path.GetFileNameWithoutExtension(_targetPath);
}

var outputFileNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
Expand Down Expand Up @@ -902,9 +894,9 @@ private void AddOutputFiles(Packaging.PackageBuilder builder)
}
else
{
if (Directory.Exists(TargetPath))
if (Directory.Exists(_targetPath))
{
targetFolder = Path.Combine(ReferenceFolder, Path.GetDirectoryName(file.Replace(TargetPath, string.Empty)));
targetFolder = Path.Combine(ReferenceFolder, Path.GetDirectoryName(file.Replace(_targetPath, string.Empty)));
}
else if (nugetFramework == null)
{
Expand Down Expand Up @@ -1002,7 +994,7 @@ private void ProcessDependencies(Packaging.PackageBuilder builder)
{
builder.DependencyGroups.Clear();

var targetFramework = TargetFramework ?? NuGetFramework.AnyFramework;
var targetFramework = _targetFramework ?? NuGetFramework.AnyFramework;
builder.DependencyGroups.Add(new PackageDependencyGroup(targetFramework, new HashSet<PackageDependency>(dependencies.Values)));
}
}
Expand Down Expand Up @@ -1048,7 +1040,7 @@ private void AddDependencies(Dictionary<string, Tuple<PackageReaderBase, Packagi

if (!props.ContainsKey(NuGetProjectMetadataKeys.TargetFramework))
{
props.Add(NuGetProjectMetadataKeys.TargetFramework, TargetFramework);
props.Add(NuGetProjectMetadataKeys.TargetFramework, _targetFramework);
}
if (!props.ContainsKey(NuGetProjectMetadataKeys.Name))
{
Expand Down