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

execute CoreBuild to generate xaml files #2982

Closed
wants to merge 1 commit into from
Closed
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 @@ -32,6 +32,54 @@ public string[] Targets
get { return _buildTargets.ToArray(); }
}

#if DEBUG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this code? It doesn't seem to be called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for debugging the tasks that MSBuild will process.

public string[] GetExecutedTargets()
{
return TopologicalSorter.TopologicalSort(this.Targets, t => GetTargetDependents(_project, t)).ToArray();
}

public string[] GetAllTargets()
{
return TopologicalSorter.TopologicalSort(GetTopLevelTargets(_project), t => GetTargetDependents(_project, t)).ToArray();
}

public string[] GetDependingTargets(string target)
{
var map = GetReverseTargetMap();

List<string> dependers;
if (map.TryGetValue(target, out dependers))
{
return dependers.ToArray();
}

return new string[0];
}

public Dictionary<string, List<string>> GetReverseTargetMap()
{
var targets = GetAllTargets();

var reverseMap = new Dictionary<string, List<string>>();
foreach (var t in targets)
{
foreach (var dependant in GetTargetDependents(_project, t))
{
List<string> dependers;
if (!reverseMap.TryGetValue(dependant, out dependers))
{
dependers = new List<string>();
reverseMap.Add(dependant, dependers);
}

dependers.Add(t);
}
}

return reverseMap;
}
#endif

/// <summary>
/// Remove the specified target from the build targets.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,18 @@ public string GetPropertyValue(string name)

protected async Task<ProjectInstance> BuildAsync(string taskName, MSB.Framework.ITaskHost taskHost, CancellationToken cancellationToken)
{
// prepare for building
var buildTargets = new BuildTargets(_loadedProject, "Compile");
// Create a project instance to be executed by build engine.
// The executed project will hold the final model of the project after execution via msbuild.
var executedProject = _loadedProject.CreateProjectInstance();

// if the project doesn't have a Compile target, then its not really a vb or c# project.
if (!executedProject.Targets.ContainsKey("Compile"))
{
return executedProject;
}

// prepare for building -- use CoreBuild to get xaml generated files
var buildTargets = new BuildTargets(_loadedProject, "CoreBuild");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to write tests for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a test, but it is skipped due to redirect problem with MSBuild. We cannot supply the correct redirects to xunit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KevinH-MS mentioned that you can add a TestAssemblyName.dll.config file, and xunit will apply it's contents when running tests for that assembly. Does that work here?


// Don't execute this one. It will build referenced projects.
// Even when DesignTimeBuild is defined, it will still add the referenced project's output to the references list
Expand All @@ -66,22 +76,12 @@ protected async Task<ProjectInstance> BuildAsync(string taskName, MSB.Framework.
// already done everything we need to compute compiler inputs by then.
buildTargets.RemoveAfter("CoreCompile", includeTargetInRemoval: false);

// create a project instance to be executed by build engine.
// The executed project will hold the final model of the project after execution via msbuild.
var executedProject = _loadedProject.CreateProjectInstance();

if (!executedProject.Targets.ContainsKey("Compile"))
{
return executedProject;
}

var hostServices = new Microsoft.Build.Execution.HostServices();

// connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task.
hostServices.RegisterHostObject(_loadedProject.FullPath, "CoreCompile", taskName, taskHost);

var buildParameters = new MSB.Execution.BuildParameters(_loadedProject.ProjectCollection);

var buildRequestData = new MSB.Execution.BuildRequestData(executedProject, buildTargets.Targets, hostServices);

var result = await this.BuildAsync(buildParameters, buildRequestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
Expand Down