Question: obtain ProjectInstance in a right way
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Task
I have to obtain a `ProjectInstance` with build-time items and properties after build.
In case I have only one target framework everything is simple. But when I have several target frameworks defined by `TargetFrameworks` property it is not so easy because target `DispatchToInnerBuilds` performs build via other `ProjectInstance` objects.
### Current solution
So I have decided to emulate `DispatchToInnerBuilds` behavior:
```c#
void Build(Project originalProject, string[] targets)
{
var targetFrameworks = GetMultipleTargetFrameworks(originalProject);
if (targetFrameworks.Any())
{
foreach (var targetFramework in targetFrameworks)
{
// Specify TargetFramework
var actualProperties = new Dictionary(properties);
actualProperties["TargetFramework"] = targetFramework;
// Build project
var project = new Project(originalProject.Xml, actualProperties, null, _projectCollection, );
var projectInstance = _buildManager.GetProjectInstanceForBuild(project);
var buildRequestData = new BuildRequestData(projectInstance, targets, null, BuildRequestDataFlags.ProvideProjectStateAfterBuild);
var request = _buildManager.PendBuildRequest(buildRequestData);
request.ExecuteAsync(submission => { ... }, null);
}
}
else
{
...
}
}
```
After executing build in that way I have several `ProjectInstance` objects corresponding to project target frameworks.
### Problem
Usually it is ok, but I do not run outer build in that way. And this approach does not work with `NuGet.Build.Tasks.Pack.targets`.
There is a next target there:
```xml
```
And in my case I run builds only with `IsInnerBuild = true`.
### Possible solutions (as far as I can see)
1. Do not emulate `DispatchToInnerBuilds` and obtain `ProjectInstance` somehow. (how?)
2. Run outer build, but without invoking `DispatchToInnerBuilds` target. (how?)
Thanks for any suggestions. Maybe someone knows how to solve the issue in a **right** way...
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.