繁体   English   中英

VS2017 Nuget软件包在编译时已复制到bin \\ debug但未复制到bin \\ release

[英]VS2017 Nuget Packages copied to bin\debug but not bin\release on compile

我的项目中包含3个Nuget软件包。 当我构建“调试”版本时,dll被复制到bin \\ debug目录中,并且项目可以正确编译。

但是,当我尝试构建发行版本时,得到了“找不到类型或名称空间名称” packagename”。

项目.csproj文件如下:

 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DocumentationFile>bin\Debug\MyProject.XML</DocumentationFile>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <DocumentationFile>bin\Release\MyProject.XML</DocumentationFile>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    </Reference>
    <Reference Include="Excel, Version=2.1.2.3, Culture=neutral, PublicKeyToken=93517dbe6a4012fa, processorArchitecture=MSIL">
    </Reference>
    <Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
    </Reference>
  </ItemGroup>

我在所有三个页面上都得到了相同的错误消息,并且它们仅是我得到的错误与不存在的错误有关。 没有其他编译错误。

对于每个这些dll,调试版本的路径(属性)是bin \\ Debug目录,但是我不知道如何设置它。

我不确定如何将这些程序包放入我的bin \\ release目录中(而不是手动复制它们)。 有人可以解释我错过了什么,或者做错了什么。

谢谢你的回复。 我已经解决了这个问题,并提高了我对所有工作原理的理解。

Nuget将获取软件包并将其放入解决方案目录中的packages目录中。 还将以下package.config文件添加到解决方案目录:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="DocumentFormat.OpenXml" version="2.5" targetFramework="net45" />
  <package id="ExcelDataReader" version="2.1.2.3" targetFramework="net45" />
  <package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
</packages>

.csproj文件中的“ HintPath”。 编译器使用它,为程序集文件提供源位置,并根据需要将其复制到relevent bin \\ Debug或bin \\ Release目录中:

 <ItemGroup>
  <Reference Include="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <HintPath>packages\DocumentFormat.OpenXml.2.5\lib\DocumentFormat.OpenXml.dll</HintPath>
  </Reference>
  <Reference Include="Excel, Version=2.1.2.3, Culture=neutral, PublicKeyToken=93517dbe6a4012fa, processorArchitecture=MSIL">
    <HintPath>packages\ExcelDataReader.2.1.2.3\lib\net45\Excel.dll</HintPath>
  </Reference>
  <Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
    <HintPath>packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
  </Reference>
</ItemGroup>

我的问题是我删除了“ HintPath”,因为它直接指向错误,然后什么也没有用。 我的bin \\ Debug中的程序集从那里构建了引用错误的程序集文件集的调试版本。 上面的代码块现在可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM