簡體   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