Reputation: 13
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:
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
Upvotes: 1
Views: 382
Reputation: 13
I was able to take a glimpse of the internal code: Both options are explicitly deprecated and the error is filed as a documentation/api bug.
Upvotes: 0
Reputation: 417
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.
Upvotes: 1