1

我想编写一个 Visual Studio 宏来关闭给定 C++ 项目的优化。有没有人有示例代码来改变项目设置?并假设项目设置作为某种值字典公开,项目的 C++ 和链接器优化的键和值是什么?

4

2 回答 2

1

Visual C++ 项目模型:

http://msdn.microsoft.com/en-us/library/2eydyk57.aspx

一些被破解的宏代码:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports Microsoft.VisualStudio.VCProjectEngine
Imports System.Text


Public Module RecordingModule

    Sub DisableOptimizationsInAllProjectsReleaseWin32()
        For i = 1 To DTE.Solution.Projects.Count
            Dim proj As Object = DTE.Solution.Projects.Item(i).Object
            On Error Resume Next
            Dim prj As VCProject = CType(proj, Microsoft.VisualStudio.VCProjectEngine.VCProject)
            If Not prj Is Nothing Then
                Dim cfgs As IVCCollection = CType(prj.Configurations, Microsoft.VisualStudio.VCProjectEngine.IVCCollection)

                For c = 1 To cfgs.Count
                    Dim cfg As VCConfiguration = CType(cfgs.Item(c), Microsoft.VisualStudio.VCProjectEngine.VCConfiguration)
                    If cfg.Name = "Release|Win32" Then
                        Dim tool As VCCLCompilerTool = CType(cfg.Tools("VCCLCompilerTool"), Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)
                        If Not tool Is Nothing Then tool.Optimization = optimizeOption.optimizeDisabled

                        Dim linker As VCLinkerTool = CType(cfg.Tools("VCLinkerTool"), Microsoft.VisualStudio.VCProjectEngine.VCLinkerTool)
                        If Not linker Is Nothing Then
                            linker.EnableCOMDATFolding = optFoldingType.optFoldingDefault
                            linker.LinkTimeCodeGeneration = LinkTimeCodeGenerationOption.LinkTimeCodeGenerationOptionDefault
                            linker.OptimizeReferences = optRefType.optReferencesDefault
                            linker.InlineFunctionExpansion = "0"
                            linker.EnableIntrinsicFunctions = "false"
                            linker.FavorSizeOrSpeed = "0"
                            linker.WholeProgramOptimization = "false"

                        End If
                        Exit For
                    End If
                Next
            End If
        Next
    End Sub
End Module
于 2011-03-30T10:34:45.277 回答
0

来自@mackenir 的答案的修改代码 - 对于当前项目:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.Text
Imports Microsoft.VisualStudio.VCProjectEngine
' Add Reference to Microsoft.VisualStudio.VCProjectEngine: Project > Add Refrence

Public Module Build

Sub CheckBuild()

    Dim Prj As Object = DTE.ActiveSolutionProjects(0).Object
    If Prj Is Nothing Then Return
    Dim VPrj As VCProject = CType(Prj, Microsoft.VisualStudio.VCProjectEngine.VCProject)
    If VPrj Is Nothing Then Return
    Dim Cfg As VCConfiguration = CType(VPrj.Configurations.Item("Debug|x64"), Microsoft.VisualStudio.VCProjectEngine.VCConfiguration)
    If Cfg Is Nothing Then Return
    Dim CTool As VCCLCompilerTool = CType(Cfg.Tools("VCCLCompilerTool"), Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)
    If CTool Is Nothing Then Return
    Dim LTool As VCLinkerTool = CType(Cfg.Tools("VCLinkerTool"), Microsoft.VisualStudio.VCProjectEngine.VCLinkerTool)
    If LTool Is Nothing Then Return

    CTool.DebugInformationFormat = debugOption.debugDisabled
    LTool.GenerateDebugInformation = "false"
    LTool.OptimizeReferences = optRefType.optNoReferences
    LTool.EnableCOMDATFolding = optFoldingType.optNoFolding

    ExecuteCommand("Build.BuildSelection")

End Sub
于 2012-10-04T18:03:53.937 回答