Visual Studio 扩展:使用 VCFileConfiguration 编译文件失败
Visual Studio Extension: Compile file with VCFileConfiguration fails
我正在编写一个简单的 C# Visual Studio 扩展,我需要在其中使用当前项目配置编译 C++ 文件。我尝试使用 VCFileConfiguration.Compile 来完成这项任务。如果我将 waitOnBuild 参数设置为 false,它工作正常。如果我将其设置为 true 以实现阻塞调用,我将得到一个 Microsoft.VisualStudio.ProjectSystem.ProjectException 异常,无论该文件是否可以正确编译。
这是一个错误还是我需要设置什么特别的东西?
到目前为止我的代码(剥离错误处理):
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 build failed."
- 来源: "Microsoft.VisualStudio.ProjectSystem.Utilities.v14.0"
调用堆栈:
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
首先:尝试重新启动Visual Studio和您的计算机 - 这是针对您的问题的最常见解决方案。
如果上述方法没有帮助:尝试清理解决方案并删除 "vspscc" 和 "vssscc" 文件,然后重新启动 VS 和 "Rebuild All".
最终选择:在Visual Studio“
Tools / Options / Projects and Solutions / Build and Run setting area:
Try to change
"MSBuild project build output verbosity" to "Diagnostic"
这样您就可以确定项目中出现的问题。
我能够瞥见内部代码:这两个选项都被明确弃用,错误被归档为 documentation/api 错误。
我正在编写一个简单的 C# Visual Studio 扩展,我需要在其中使用当前项目配置编译 C++ 文件。我尝试使用 VCFileConfiguration.Compile 来完成这项任务。如果我将 waitOnBuild 参数设置为 false,它工作正常。如果我将其设置为 true 以实现阻塞调用,我将得到一个 Microsoft.VisualStudio.ProjectSystem.ProjectException 异常,无论该文件是否可以正确编译。
这是一个错误还是我需要设置什么特别的东西?
到目前为止我的代码(剥离错误处理):
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 build failed."
- 来源: "Microsoft.VisualStudio.ProjectSystem.Utilities.v14.0"
调用堆栈:
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
首先:尝试重新启动Visual Studio和您的计算机 - 这是针对您的问题的最常见解决方案。
如果上述方法没有帮助:尝试清理解决方案并删除 "vspscc" 和 "vssscc" 文件,然后重新启动 VS 和 "Rebuild All".
最终选择:在Visual Studio“
Tools / Options / Projects and Solutions / Build and Run setting area: Try to change
"MSBuild project build output verbosity" to "Diagnostic"
这样您就可以确定项目中出现的问题。
我能够瞥见内部代码:这两个选项都被明确弃用,错误被归档为 documentation/api 错误。