Domanda

Quale sarebbe il modo per recuperare la cartella SDK di Windows in un'attività MSBuild?

Utilizzando l'attività generateBootstrapper sto creando un bootstrapper per la mia installazione per poter installare i pre-requisiti. Questa attività richiede il percorso della cartella in cui si trovano i pacchetti prerequisiti, ovvero la cartella SDK di Windows

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\"

quando uso Visual Studio 2008. Finora ho usato un percorso hard-coded ma questo non funzionerà su nessun sistema. C'è un modo migliore per ottenere il percorso?

Questo è il mio script di build:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 
         ToolsVersion="3.5">
    <ItemGroup>
        <BootstrapperFile Include="Microsoft.Net.Framework.2.0">
            <ProductName>.NET Framework 2.0</ProductName>
        </BootstrapperFile>
        <BootstrapperFile Include="Microsoft.Windows.Installer.3.1">
            <ProductName>Windows Installer 3.1</ProductName>
        </BootstrapperFile>
    </ItemGroup>

    <Target Name="Bootstrapper">
        <GenerateBootstrapper ApplicationFile="mySetup.msi" 
            Culture="de-DE" 
            ApplicationName="My Application" 
            OutputPath="$(OutDir)\de-DE" 
            BootstrapperItems="@(BootstrapperFile)" 
            Path="C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\" />

        <GenerateBootstrapper ApplicationFile="mySetup.msi" 
            Culture="en-US" 
            ApplicationName="My Application" 
            OutputPath="$(OutDir)\en-US" 
            BootstrapperItems="@(BootstrapperFile)" 
            Path="C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\" />
    </Target>
</Project>
È stato utile?

Soluzione

Puoi anche utilizzare l'attività GetFrameworkSdkPath MSBuild.

<GetFrameworkSdkPath>
  <Output TaskParameter="Path" PropertyName="WindowsSdkPath" />
</GetFrameworkSdkPath>  

Ad esempio:

<GenerateBootstrapper 
  ApplicationFile="$(SolutionName).application"
  ApplicationName="$(ClickOnceAppTitle)"
  ApplicationUrl="$(ClickOnceUrl)"
  BootstrapperItems="@(BootstrapperFile)"
  Culture="en"
  FallbackCulture="en-US"
  Path="$(WindowsSDKPath)"
  OutputPath="." /> 

Altri suggerimenti

grazie John. Secondo il tuo post ho modificato lo script MSBuild per leggere la cartella dal registro. Non era tuttavia necessario aggiungere "Pacchetti" alla fine, è stato un altro errore nella mia sceneggiatura originale.

Quello che segue è lo script funzionante:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <WindowsSDKPath>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GenericBootstrapper\3.5@Path)</WindowsSDKPath>
    </PropertyGroup>

    <ItemGroup>
        <BootstrapperFile Include="Microsoft.Net.Framework.2.0">
                <ProductName>.NET Framework 2.0</ProductName>
        </BootstrapperFile>
        <BootstrapperFile Include="Microsoft.Windows.Installer.3.1">
                <ProductName>Windows Installer 3.1</ProductName>
        </BootstrapperFile>
    </ItemGroup>

    <Target Name="Bootstrapper">
        <GenerateBootstrapper ApplicationFile="mySetup.msi" 
            Culture="de-DE" 
            ApplicationName="My Application" 
            OutputPath="$(OutDir)\de-DE" 
            BootstrapperItems="@(BootstrapperFile)" 
            Path="$(WindowsSDKPath)" />

        <GenerateBootstrapper ApplicationFile="mySetup.msi" 
            Culture="en-US" 
            ApplicationName="My Application" 
            OutputPath="$(OutDir)\en-US" 
            BootstrapperItems="@(BootstrapperFile)" 
            Path="$(WindowsSDKPath)" />
    </Target>
</Project>

Il percorso di installazione di Windows SDK è archiviato nel valore CurrentInstallFolder della seguente chiave di registro:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SDKs \ Windows

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SDKs \ Windows CurrentInstallFolder

Ho seguito la risposta di Jeremy D, ma questo ha dato il messaggio di errore:     errore MSB3147: impossibile trovare il file richiesto 'setup.bin' in 'C: \ Programmi (x86) \ Microsoft SDKs \ Windows \ v8.0A \ Engine'.

Il motivo è che il percorso del bootstrapper (almeno con V8.0A dell'SDK) è una sottodirectory nel percorso restituito da GetFrameworkSdKPath.

Quindi il codice MSBuild che funziona per me è:

<Target Name="AfterBuild">
  <GetFrameworkSdkPath>
    <Output TaskParameter="Path" PropertyName="WindowsSdkPath"/>
  </GetFrameworkSdkPath>
  <GenerateBootstrapper 
      ApplicationFile="myapp.msi" 
      ApplicationName="MyApplication" 
      BootstrapperItems="@(BootstrapperFile)" 
      OutputPath="$(OutputPath)" 
      Path="$(WindowsSdkPath)\Bootstrapper" />
</Target>

Nota il suffisso \ Bootstrapper su $ (WindowsSdkPath)

Il percorso del bootstrapper è archiviato nella chiave di registro:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GenericBootstrapper\3.5

Per scoprire la cartella dei pacchetti, aprila, leggi il " Percorso " valore di registro e aggiungere " Pacchetti " alla fine e questo dovrebbe darti il ??percorso completo della cartella che desideri.

Ad esempio:

string bootStrapperPackagesFolder = "";

RegistryKey regKey = Registry.LocalMachine.OpenSubKey
   (@"SOFTWARE\Microsoft\GenericBootstrapper\3.5");
if (regKey != null)
{
   bootStrapperPackagesFolder = (string)regKey.GetValue("Path");
   if (bootStrapperPackagesFolder != null)
   {
      bootStrapperPackagesFolder += @"Packages\";
      Console.WriteLine(bootStrapperPackagesFolder);
   }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top