I am writing a simple C# Visual Studio extension in which I need to compile C++ files with the current project configuration. I tried to use VCFileConfiguration.Compile for this task. It works fine if I set the waitOnBuild parameter to false. If I set it true to achieve a blocking call, I get a Microsoft.VisualStudio.ProjectSystem.ProjectException exception, no matter if the file can be compiled without errors or not.
Is this a bug or is there anything special I need to setup?
My code so far (stripped error handling):
var projectItem = dte.ActiveDocument.ProjectItem; var project = projectItem.ContainingProject; VCProject vcProject = (VCProject)project.Object; VCConfiguration activeConfiguration = vcProject.ActiveConfiguration; VCFile vcFile = projectItem.Object as VCFile; IVCCollection fileConfigCollection = vcFile.FileConfigurations; VCFileConfiguration fileConfig = fileConfigCollection.Item(activeConfiguration.Name); try { fileConfig.Compile(false, true); } catch (Microsoft.VisualStudio.ProjectSystem.ProjectException exception) { // Fails all the time if waitOnBuild == true } The exception in Detail:
- Message: "The build failed."
- Source: "Microsoft.VisualStudio.ProjectSystem.Utilities.v14.0"
Callstack:
at Microsoft.VisualStudio.ProjectSystem.Utilities.ProjectErrorUtilities.ThrowProjectExceptionHelper(Exception innerException, String unformattedMessage, Object[] args) at Microsoft.VisualStudio.ProjectSystem.Utilities.ProjectErrorUtilities.ThrowProjectException(String message) at Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCFileConfigurationShim.<>c__DisplayClass4_0.<<Compile>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.ApartmentMarshaler.<>c__DisplayClass7_0.<<Invoke>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread() at Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.ApartmentMarshaler.Invoke(Func`1 method) at Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCFileConfigurationShim.Compile(Boolean forceBuild, Boolean waitOnBuild) at IncludeFormatter.Commands.PurgeIncludes.MenuItemCallback(Object sender, EventArgs e) in C:\Users\Andreas\Development\current_development\IncludeFormatter\IncludeFormatter\Commands\PurgeIncludes.cs:line 144 1 Answers
Answers 1
First: Try Restarting Visual Studio and your computer - this is the most common solution for your problem.
If the above doesn't help: Try to clean the solution and remove "vspscc" and "vssscc" files, and then restart VS and "Rebuild All".
Final option: In Visual Studio "
Tools / Options / Projects and Solutions / Build and Run setting area: Try to change
"MSBuild project build output verbosity" to "Diagnostic"
so you can determine what is failing in your project.
0 comments:
Post a Comment