1 回答

TA貢獻1862條經(jīng)驗 獲得超6個贊
Nuget:包含一個 exe 作為運行時依賴項
首先,我知道你想為未來使用一些技術(shù),但我們要知道,這些面向未來的技術(shù)往往有一定的限制和條件。
例如,<contentFiles>用于NuGet 4.0 + 和PackageReference,Visual Studio 2015不支持它們。有關(guān)詳細信息,請參閱將 contentFiles 元素用于內(nèi)容文件。
如果您對此感興趣<contentFiles>,可以閱讀博客NuGet 現(xiàn)在已完全集成到 MSBuild 中。
現(xiàn)在回到我們的問題,根據(jù)上面的信息,我們<contentFiles>在使用Visual Studio 2015時不應(yīng)該使用。 為了解決這個問題,我們需要.targets在構(gòu)建項目時在nuget包中添加一個文件:
.targets文件內(nèi)容:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(ProjectDir)myexe.exe">
<Link>myexe.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CustomToolNamespace></CustomToolNamespace>
</None>
</ItemGroup>
</Project>
該.nuspec文件類似以下內(nèi)容:
<files>
<file src="build\YouNuGetPackageName.targets" target="build\YouNuGetPackageName.targets" />
<file src="content\myexe.exe" target="content\myexe.exe" />
</files>
注意: .targets 文件的名稱應(yīng)與您的 nuget 包名稱相同。
通過這種方式,當您構(gòu)建項目時,MSBuild/VS 會將文件復(fù)制myexe.exe到輸出文件夾。
此外,如果要將文件復(fù)制myexe.exe到其他目的地,可以.targets使用復(fù)制任務(wù)替換文件內(nèi)容,例如:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyMyexe" BeforeTargets="Build">
<Message Text="Copy CopyMyexe to the folder."></Message>
<Copy
SourceFiles="$(ProjectDir)myexe.exe"
DestinationFolder="xxx\xxx\xx\myexe.exe"
/>
</Target>
</Project>
有關(guān)一些幫助,請參閱創(chuàng)建本機包和類似問題。
希望這可以幫助。
- 1 回答
- 0 關(guān)注
- 247 瀏覽
添加回答
舉報