Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 更改nuget包的输出目录_.net_Nuget_Nuget Package - Fatal编程技术网

.net 更改nuget包的输出目录

.net 更改nuget包的输出目录,.net,nuget,nuget-package,.net,Nuget,Nuget Package,我从我的项目中创建了一个NuGet包。包的输出目录是解决方案目录。我想把它输出到一个特定的目录。我在csproj文件和nuspec文件中尝试了一个目标。没有一个奏效。如何获取在指定文件夹中生成的包 在my.csproj中: <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <PropertyGroup> <ErrorText>This pro

我从我的项目中创建了一个NuGet包。包的输出目录是解决方案目录。我想把它输出到一个特定的目录。我在csproj文件和nuspec文件中尝试了一个目标。没有一个奏效。如何获取在指定文件夹中生成的包

在my.csproj中:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
    <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
  </PropertyGroup>
  <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>

此项目引用此计算机上缺少的NuGet包。启用NuGet软件包还原以下载它们。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105. 缺少的文件是{0}。
在我的.nuspec中:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>MyPackage.dll</id>
    <version>1.0.0</version>
    <authors>me</authors>
    <owners>me</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2016</copyright>
    <files>
      <file src="bin\MyPackage.dll" target="C:\LocalPackageRepository" />
    </files>
  </metadata>
</package>

MyPackage.dll
1.0.0
我
我
假的
包装说明
此版本包中所做更改的摘要。
版权所有2016

无法从.nuspec文件执行此操作。您可以创建一个NuGet.Config文件,并为所有解决方案定义一个全局包目录:

<configuration>
  <config>
    <add key="repositoryPath" value="C:\myteam\teampackages" />
  </config>
  ... 
</configuration>

有关此功能的更多详细信息。

以NuGet的“旧”方式(您似乎在使用,请检查有关新与旧的信息),可以使用您提到的.NuGet\NuGet.targets文件中的命令。如果将带有PackageOutputDir的行更改为下面的行,则该行将正常工作

<PackageOutputDir Condition="$(PackageOutputDir) == ''">C:\LocalPackageRepository</PackageOutputDir>
C:\LocalPackageRepository
更好的做法是在.csproj中的PropertyGroup上设置如下属性:

<PackageOutputDir>C:\LocalPackageRepository</PackageOutputDir>
C:\LocalPackageRepository
在NuGet的新方式中,您可以将此密钥添加到NuGet.config文件:

<add key="repositoryPath" value="C:\LocalPackageRepository" />

不确定为什么全局配置设置对我不起作用,但添加以下解决方案解决了我的问题:

  • 在用户变量下创建环境变量:
  • 然后将以下设置添加到.csproj文件:

参考:

更新 目前我正在使用下面的代码,它更简单,但它将所有.nupkg文件复制到“本地”路径



无法从.nuspec文件执行此操作。您可以创建一个NuGet.Config文件,并为所有解决方案定义一个全局包目录。这在.nupkg文件之外完成,并存储在您的配置文件下或子目录中,该子目录是包含解决方案的所有目录的父目录。请参阅此功能上的NuGet。
repositoryPath
的问题在于,NuGet还希望依赖项包位于那里,因此它的变化不仅仅限于输出目录。PackageOutputDir在2021年在.net 6中创建的NuGet项目中工作得很好。请注意,nuget包的输出路径和build的输出路径是不同的。构建位于目标框架的目录中,nuget包文件位于其上方的一个目录中。例如,包在
bin\Release\
中,
OutputPath
bin\Release\{targetframework}
@DouglasGaskell是的,当然,目前我使用的是更新答案中提到的更简单的版本。
Variable name: MyNugetsOutput
Variable value: D:\myteam\teampackages