Build single project only with MSBuild BuildManager












0














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)










share|improve this question
























  • 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 '18 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 '18 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 '18 at 7:30
















0














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)










share|improve this question
























  • 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 '18 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 '18 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 '18 at 7:30














0












0








0







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)










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 12:26

























asked Nov 19 '18 at 12:17









Pawcio

114




114












  • 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 7:30

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














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





















































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







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]