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

expand pattern to report missing files #11238

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,62 @@ public async Task MissingTargetsAreReported()
Assert.Equal(Path.Combine(temporaryDirectory.DirectoryPath, "this.file.does.not.exist.targets"), result.ErrorDetails!.ToString());
}

[Fact]
public async Task MissingVisualStudioComponentTargetsAreReportedAsMissingFiles()
{
using var temporaryDirectory = await TemporaryDirectory.CreateWithContentsAsync(
[
("project.csproj", """
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Some.Visual.Studio.Component.props" />
<PropertyGroup>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="Some.Package, Version=1.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>packages\Some.Package.1.0.0\lib\net45\Some.Package.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
"""),
("packages.config", """
<packages>
<package id="Some.Package" version="1.0.0" targetFramework="net45" />
</packages>
"""),
("NuGet.Config", """
<configuration>
<packageSources>
<clear />
<add key="private_feed" value="packages" />
</packageSources>
</configuration>
""")
]
);
MockNuGetPackage[] packages =
[
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net45"),
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.1.0", "net45"),
];
await MockNuGetPackagesInDirectory(packages, Path.Combine(temporaryDirectory.DirectoryPath, "packages"));
var resultOutputPath = Path.Combine(temporaryDirectory.DirectoryPath, "result.json");

var worker = new UpdaterWorker(new ExperimentsManager(), new TestLogger());
await worker.RunAsync(temporaryDirectory.DirectoryPath, "project.csproj", "Some.Package", "1.0.0", "1.1.0", isTransitive: false, resultOutputPath: resultOutputPath);

var resultContents = await File.ReadAllTextAsync(resultOutputPath);
var result = JsonSerializer.Deserialize<UpdateOperationResult>(resultContents, UpdaterWorker.SerializerOptions)!;
Assert.Equal(ErrorType.MissingFile, result.ErrorType);
Assert.Equal("$(MSBuildExtensionsPath32)/Microsoft/VisualStudio/v$(VisualStudioVersion)/Some.Visual.Studio.Component.props", result.ErrorDetails!.ToString().NormalizePathToUnix());
}

[Fact]
public async Task ReportsPrivateSourceAuthenticationFailure()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,13 @@ internal static void ThrowOnUnauthenticatedFeed(string stdout)

internal static string? GetMissingFile(string output)
{
var missingFilePattern = new Regex(@"The imported project \""(?<FilePath>.*)\"" was not found");
var match = missingFilePattern.Match(output);
if (match.Success)
var missingFilePatterns = new[]
{
new Regex(@"The imported project \""(?<FilePath>.*)\"" was not found"),
new Regex(@"The imported file \""(?<FilePath>.*)\"" does not exist"),
};
var match = missingFilePatterns.Select(p => p.Match(output)).Where(m => m.Success).FirstOrDefault();
if (match is not null)
{
return match.Groups["FilePath"].Value;
}
Expand Down
Loading