Delete Key in LookInFolders VS 2008 - 9.0 using Ms

2019-09-04 15:05发布

问题:

I use MsBuild to Registry a VS Addin.

I need implement target Uninstall in MSBuild.

How can I delete my addin path in SOFTWARE\Microsoft\VisualStudio\9.0\AutomationOptions\LookInFolders registry using MsBuild ?

For install, I use

    <Target Name="RegistryExtensions">

            <Message Text="Registry AddIn..."></Message>
            <Registry.Set
                RegistryHive="LocalMachine"
                Key="SOFTWARE\Microsoft\VisualStudio\9.0\AutomationOptions\LookInFolders"
                Value="$(ProgramFiles)\LifeCycle\AddIns"
                DataType="String" />

            <Message Text="Adding LifeCycle.targets to VisualStudio SafeImports ..."></Message>
            <Registry.Set
                RegistryHive="LocalMachine"
                Key="SOFTWARE\Microsoft\VisualStudio\9.0\MSBuild\SafeImports"
                Value="MyLifeCycle"
                DataType="String"
                Data="$(MSBuildExtensionsPath)\LifeCycle.targets" ContinueOnError="true">
            </Registry.Set>
        </Target>

    <Target Name="UnRegistryAddin">
<!-- TODO -->
        </Target>

I try get the value, but I get Empty string

    <Registry.GetKey
        RegistryHive="LocalMachine"
        Key="SOFTWARE\Microsoft\VisualStudio\9.0\AutomationOptions\LookInFolders"
        Value="$(ProgramFiles)\LifeCycle\AddIns">
        <Output TaskParameter="Data" PropertyName="Addin1"/>
    </Registry.GetKey>

    <Message Text=" Addin1 $(Addin1)" />

回答1:

You can sue DeleteKey/DeleteKeyTree Registry tasks, see MSBuild Extension Pack help

<!-- Delete a key -->
        <MSBuild.ExtensionPack.Computer.Registry 
           TaskAction="DeleteKey" 
           RegistryHive="LocalMachine" 
           Key="SOFTWARE\ANewTemp"/>

I believe it should work with the syntax you are used for the Set task:

<Registry.DeleteKey ...

Important (required attributes to be set):

  • DeleteKey (Required: RegistryHive, Key)
  • DeleteKeyTree (Required: RegistryHive, Key)