Share via


SignFile 工作

使用指定的憑證對指定的檔案簽章。

參數

下表說明 SignFile 工作的參數。

參數

描述

CertificateThumbprint

必要的 String 參數。

指定用於簽署的憑證。 這個憑證必須在目前使用者的個人存放區中。

SigningTarget

必要的 ITaskItem 參數。

指定要使用憑證簽署的檔案。

TimestampUrl

選擇性 String 參數。

指定時間戳記伺服器的 URL。

備註

除了以上列出的參數之外,此項工作還會繼承 Task 類別的參數。 如需這些其他參數的清單及其描述,請參閱 工作基底類別

範例

下列範例會使用 SignFile 工作搭配 Certificate 屬性指定的憑證,以簽署 FilesToSign 項目集合指定的檔案。

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

    <ItemGroup>
        <FileToSign Include="File.exe" />
    </ItemGroup>

    <PropertyGroup>
        <Certificate>Cert.cer</Certificate>
    </PropertyGroup>

    <Target Name="Sign">
        <SignFile
            CertificateThumbprint="$(CertificateThumbprint)"
            SigningTarget="@(FileToSign)" />
    </Target>

</Project>
注意事項注意事項

憑證指模是憑證的 SHA1 雜湊。如需詳細資訊,請參閱取得受信任根 CA 憑證的 SHA-1 雜湊

下列範例會使用 Exec 工作搭配 Certificate 屬性指定的憑證,以簽署 FilesToSign 項目集合指定的檔案。 您可以使用這個在組建程序期間簽署 Windows 安裝程式檔案。

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

    <ItemGroup>
        <FileToSign Include="File.msi" />
    </ItemGroup>

    <PropertyGroup>
        <Certificate>Cert.cer</Certificate>
    </PropertyGroup>

    <Target Name="Sign">
        <Exec Command="signtool.exe sign /f CertFile /p Password "@(FileToSign)" "/>
    </Target>

</Project>

請參閱

概念

MSBuild 工作

其他資源

MSBuild 工作參考