[英]Copy nuget package content file (of type .exe) to output directory of project using that nuget package
我有一些項目有一些 exe 作為“依賴項”,我從.csproj
文件將該項目構建為 nuget package
文件看起來像這樣:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>1.1.2</Version>
<PackageId>MyLib</PackageId>
<Authors>me</Authors>
<Company>me</Company>
</PropertyGroup>
<ItemGroup>
<None Remove="CliInterface\32BitInterface.exe" />
</ItemGroup>
<ItemGroup>
<Content Include="CliInterface\32BitInterface.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PrivateAssets>analyzers;build</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
當我在其他一些解決方案中使用 nuget package 時,我可以看到文件在那里
但是它不會復制到 output 文件夾。 事實上,正確的是,當我從Visual Studio
運行Build
項目時,但我在我的CI/CD
環境中使用do.net build
命令,並且當我運行該命令時它沒有被復制到 output。
編輯:我還注意到該 exe 的位置位於 %USERPROFILE%.nuget 文件夾內,我的 csproj 文件(來自其他解決方案,引用了 nuget 包)具有硬編碼路徑,其中包含我的用戶名。 我不確定為什么會這樣,但不喜歡那樣
相反,嘗試使用這個
<PackageCopyToOutput>true</PackageCopyToOutput>
在csproj
文件中添加這些:
<ItemGroup>
<Content Include="CliInterface\32BitInterface.exe">
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
</ItemGroup>
然后重新打包您的 lib 項目。 當您嘗試安裝這個新發布版本時,請不要忘記先清理 nuget 緩存或刪除C:\Users\xxx(current user)\.nuget\packages
下的緩存文件。
此外,這也是一個類似的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.