Build single project only with MSBuild BuildManager
up vote
0
down vote
favorite
I have the following code which suppose to compile a project in my solution. The compilation is successful but my problem is that other projects in the solution are also compiled and I want to avoid this.
public static void msBuild(Project p) {
var pc = new Microsoft.Build.Evaluation.ProjectCollection();
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>() {
{"Configuration", "Debug" },
{"Platform", "AnyCPU" },
};
//TODO: MSBuild is compiling some other projects besides the one specified.
BuildRequestData BuidlRequest = new BuildRequestData(
p.paths.project, //this is path to project's .csproj file
GlobalProperty,
null,
new string { "Build" },
null
);
var bp = new BuildParameters(pc);
bp.Loggers = new ILogger {
new MSBuildLogger(){
Verbosity = LoggerVerbosity.Detailed,
}
};
bp.DetailedSummary = true;
log($"********Compiling {p} project with MSBuild***********");
BuildManager.DefaultBuildManager.ResetCaches();
var br = BuildManager.DefaultBuildManager.Build(
bp, BuidlRequest);
logBuffer();
log("Compilation result:", br.OverallResult);
if (br.Exception != null) throw br.Exception;
}
This are some basic, modified examples from the internet. I can't say I understand how this suppose to work. I've tried to read logs but is't even hard to tell when a new projects is about to compile.
I know that this compiles other projects from the time it takes + when I produce some error in other project I can see it.
I would like to get the same behavior as I do when clicking Build on project in Solution Explorer (I have build unchecked for all projects in configurations manager)
c# visual-studio msbuild
add a comment |
up vote
0
down vote
favorite
I have the following code which suppose to compile a project in my solution. The compilation is successful but my problem is that other projects in the solution are also compiled and I want to avoid this.
public static void msBuild(Project p) {
var pc = new Microsoft.Build.Evaluation.ProjectCollection();
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>() {
{"Configuration", "Debug" },
{"Platform", "AnyCPU" },
};
//TODO: MSBuild is compiling some other projects besides the one specified.
BuildRequestData BuidlRequest = new BuildRequestData(
p.paths.project, //this is path to project's .csproj file
GlobalProperty,
null,
new string { "Build" },
null
);
var bp = new BuildParameters(pc);
bp.Loggers = new ILogger {
new MSBuildLogger(){
Verbosity = LoggerVerbosity.Detailed,
}
};
bp.DetailedSummary = true;
log($"********Compiling {p} project with MSBuild***********");
BuildManager.DefaultBuildManager.ResetCaches();
var br = BuildManager.DefaultBuildManager.Build(
bp, BuidlRequest);
logBuffer();
log("Compilation result:", br.OverallResult);
if (br.Exception != null) throw br.Exception;
}
This are some basic, modified examples from the internet. I can't say I understand how this suppose to work. I've tried to read logs but is't even hard to tell when a new projects is about to compile.
I know that this compiles other projects from the time it takes + when I produce some error in other project I can see it.
I would like to get the same behavior as I do when clicking Build on project in Solution Explorer (I have build unchecked for all projects in configurations manager)
c# visual-studio msbuild
Does thep.paths.project
means the full path of the project file? Or you define the class paths? You can try to use the ClassProjectInstance
, likeProjectInstance projectInstance = new ProjectInstance(msbuildFileName);
, check the thread:stackoverflow.com/questions/9942499/…
– Leo Liu-MSFT
Nov 20 at 3:28
I've just tried that. The result is the same - the builder complies 40 project's in solution. Strange thing is that for some other project I build with this methods, the builder works as I expect (compile single project)
– Pawcio
Nov 20 at 7:14
It seems more related to your projects, have you checked what is special about those projects? It works fine on my side. Could you test the new blank project with this method, check if you still have this issue.
– Leo Liu-MSFT
Nov 20 at 7:30
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have the following code which suppose to compile a project in my solution. The compilation is successful but my problem is that other projects in the solution are also compiled and I want to avoid this.
public static void msBuild(Project p) {
var pc = new Microsoft.Build.Evaluation.ProjectCollection();
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>() {
{"Configuration", "Debug" },
{"Platform", "AnyCPU" },
};
//TODO: MSBuild is compiling some other projects besides the one specified.
BuildRequestData BuidlRequest = new BuildRequestData(
p.paths.project, //this is path to project's .csproj file
GlobalProperty,
null,
new string { "Build" },
null
);
var bp = new BuildParameters(pc);
bp.Loggers = new ILogger {
new MSBuildLogger(){
Verbosity = LoggerVerbosity.Detailed,
}
};
bp.DetailedSummary = true;
log($"********Compiling {p} project with MSBuild***********");
BuildManager.DefaultBuildManager.ResetCaches();
var br = BuildManager.DefaultBuildManager.Build(
bp, BuidlRequest);
logBuffer();
log("Compilation result:", br.OverallResult);
if (br.Exception != null) throw br.Exception;
}
This are some basic, modified examples from the internet. I can't say I understand how this suppose to work. I've tried to read logs but is't even hard to tell when a new projects is about to compile.
I know that this compiles other projects from the time it takes + when I produce some error in other project I can see it.
I would like to get the same behavior as I do when clicking Build on project in Solution Explorer (I have build unchecked for all projects in configurations manager)
c# visual-studio msbuild
I have the following code which suppose to compile a project in my solution. The compilation is successful but my problem is that other projects in the solution are also compiled and I want to avoid this.
public static void msBuild(Project p) {
var pc = new Microsoft.Build.Evaluation.ProjectCollection();
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>() {
{"Configuration", "Debug" },
{"Platform", "AnyCPU" },
};
//TODO: MSBuild is compiling some other projects besides the one specified.
BuildRequestData BuidlRequest = new BuildRequestData(
p.paths.project, //this is path to project's .csproj file
GlobalProperty,
null,
new string { "Build" },
null
);
var bp = new BuildParameters(pc);
bp.Loggers = new ILogger {
new MSBuildLogger(){
Verbosity = LoggerVerbosity.Detailed,
}
};
bp.DetailedSummary = true;
log($"********Compiling {p} project with MSBuild***********");
BuildManager.DefaultBuildManager.ResetCaches();
var br = BuildManager.DefaultBuildManager.Build(
bp, BuidlRequest);
logBuffer();
log("Compilation result:", br.OverallResult);
if (br.Exception != null) throw br.Exception;
}
This are some basic, modified examples from the internet. I can't say I understand how this suppose to work. I've tried to read logs but is't even hard to tell when a new projects is about to compile.
I know that this compiles other projects from the time it takes + when I produce some error in other project I can see it.
I would like to get the same behavior as I do when clicking Build on project in Solution Explorer (I have build unchecked for all projects in configurations manager)
c# visual-studio msbuild
c# visual-studio msbuild
edited Nov 19 at 12:26
asked Nov 19 at 12:17
Pawcio
113
113
Does thep.paths.project
means the full path of the project file? Or you define the class paths? You can try to use the ClassProjectInstance
, likeProjectInstance projectInstance = new ProjectInstance(msbuildFileName);
, check the thread:stackoverflow.com/questions/9942499/…
– Leo Liu-MSFT
Nov 20 at 3:28
I've just tried that. The result is the same - the builder complies 40 project's in solution. Strange thing is that for some other project I build with this methods, the builder works as I expect (compile single project)
– Pawcio
Nov 20 at 7:14
It seems more related to your projects, have you checked what is special about those projects? It works fine on my side. Could you test the new blank project with this method, check if you still have this issue.
– Leo Liu-MSFT
Nov 20 at 7:30
add a comment |
Does thep.paths.project
means the full path of the project file? Or you define the class paths? You can try to use the ClassProjectInstance
, likeProjectInstance projectInstance = new ProjectInstance(msbuildFileName);
, check the thread:stackoverflow.com/questions/9942499/…
– Leo Liu-MSFT
Nov 20 at 3:28
I've just tried that. The result is the same - the builder complies 40 project's in solution. Strange thing is that for some other project I build with this methods, the builder works as I expect (compile single project)
– Pawcio
Nov 20 at 7:14
It seems more related to your projects, have you checked what is special about those projects? It works fine on my side. Could you test the new blank project with this method, check if you still have this issue.
– Leo Liu-MSFT
Nov 20 at 7:30
Does the
p.paths.project
means the full path of the project file? Or you define the class paths? You can try to use the Class ProjectInstance
, like ProjectInstance projectInstance = new ProjectInstance(msbuildFileName);
, check the thread:stackoverflow.com/questions/9942499/…– Leo Liu-MSFT
Nov 20 at 3:28
Does the
p.paths.project
means the full path of the project file? Or you define the class paths? You can try to use the Class ProjectInstance
, like ProjectInstance projectInstance = new ProjectInstance(msbuildFileName);
, check the thread:stackoverflow.com/questions/9942499/…– Leo Liu-MSFT
Nov 20 at 3:28
I've just tried that. The result is the same - the builder complies 40 project's in solution. Strange thing is that for some other project I build with this methods, the builder works as I expect (compile single project)
– Pawcio
Nov 20 at 7:14
I've just tried that. The result is the same - the builder complies 40 project's in solution. Strange thing is that for some other project I build with this methods, the builder works as I expect (compile single project)
– Pawcio
Nov 20 at 7:14
It seems more related to your projects, have you checked what is special about those projects? It works fine on my side. Could you test the new blank project with this method, check if you still have this issue.
– Leo Liu-MSFT
Nov 20 at 7:30
It seems more related to your projects, have you checked what is special about those projects? It works fine on my side. Could you test the new blank project with this method, check if you still have this issue.
– Leo Liu-MSFT
Nov 20 at 7:30
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374459%2fbuild-single-project-only-with-msbuild-buildmanager%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Does the
p.paths.project
means the full path of the project file? Or you define the class paths? You can try to use the ClassProjectInstance
, likeProjectInstance projectInstance = new ProjectInstance(msbuildFileName);
, check the thread:stackoverflow.com/questions/9942499/…– Leo Liu-MSFT
Nov 20 at 3:28
I've just tried that. The result is the same - the builder complies 40 project's in solution. Strange thing is that for some other project I build with this methods, the builder works as I expect (compile single project)
– Pawcio
Nov 20 at 7:14
It seems more related to your projects, have you checked what is special about those projects? It works fine on my side. Could you test the new blank project with this method, check if you still have this issue.
– Leo Liu-MSFT
Nov 20 at 7:30