MSBuildProjectCreator
MSBuildProjectCreator copied to clipboard
'Build' target (and .nuget.g.props) not included in binlog?
Hi again,
I am seeing some weirdness with package restore and binlog files (causing me some confusion when analyzing a totally different issue).
I made a testcase (based of an example in RepositoryTests.cs)
Basically this example is trying to:
- confirm that PackageReference is actually consumed during a build
- make a binlog of the whole process so I can do an analysis of what MSBuild is doing
However, the resulting binlog only shows the "Restore" target in the binlog, whereas I would also have expected a "Build" target in the binlog.
Also searching for PkgPackageA
in the binlog does not get any hits, even though the ClassLibraryA.csproj.nuget.g.props
contains it on disk.
This is tested with:
- VS2022 17.0.6
- MSBuildProjectCreator main branch
Note: in order to inspect the binlog file, you need to set a breakpoint to prevent automatic cleanup of the temp folder.
[Fact]
public void BuildCanConsumePackageWithGeneratePathProperty()
{
string binLogPath = Path.Combine(TestRootPath, "test.binlog");
using (PackageRepository.Create(TestRootPath)
.Package("PackageB", "1.0", out Package packageB)
.Library(TargetFramework)
.Package("PackageA", "1.0.0", out Package packageA)
.Dependency(packageB, TargetFramework)
.Library(TargetFramework))
{
using (ProjectCollection projectCollection = new ProjectCollection())
{
projectCollection.RegisterLogger(new BinaryLogger
{
Parameters = $"LogFile={binLogPath}",
});
ProjectCreator.Templates.SdkCsproj(
path: Path.Combine(TestRootPath, "ClassLibraryA", "ClassLibraryA.csproj"),
targetFramework: TargetFramework,
projectCollection: projectCollection)
.ItemPackageReference(packageA, metadata: new Dictionary<string, string>
{
{ "GeneratePathProperty", "true" },
})
.TryBuild(restore: true, out bool result, out BuildOutput buildOutput)
.TryGetPropertyValue("PkgPackageA", out string packagePath);
result.ShouldBeTrue(buildOutput.GetConsoleLog());
packagePath.ShouldNotBeEmpty();
}
// NOTE: binlog does not look correct and seems to be missing actual content for PkgPackageA
}
}