Visual Studio 2017在发布时继续使用过时的引用项目的Debug版本

时间:2017-10-09 11:20:35

标签: c# visual-studio .net-core

我的项目设置如下:

MainProject.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <RuntimeIdentifiers>win10-x64;ubuntu.16.04-x64</RuntimeIdentifiers>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Project1\Project1.csproj" />
    <ProjectReference Include="..\Project2\Project2.csproj" />
  </ItemGroup>

  <ItemGroup>
    <None Update="mark.txt">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Project1.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
    <OutputTypeEx>library</OutputTypeEx>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <Version>1.0.16</Version>
    <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    <DebugType>full</DebugType>
    <DebugSymbols>True</DebugSymbols>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard1.6|AnyCPU'">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard1.6|x64'">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
    <PackageReference Include="System.Runtime" Version="4.3.0" />
    <PackageReference Include="System.ValueTuple" Version="4.3.1" />
  </ItemGroup>
</Project>

Project2.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Project1\Project1.csproj" />
  </ItemGroup>
</Project>

我已使用Right click -> Publish配置发布项目,如下所示:

Profile Name: FolderProfile
Configuration: Release
Target Framework: netcoreapp1.1
Target Runtime: win10-x64
Target Location: bin\Release\PublishOutput\Win10

每当我尝试发布项目时(在发布模式下),Visual Studio决定使用Project1Project2的旧调试版本,而不是新版本。我已将问题追溯到Visual Studio正在执行的Roslyn csc命令。在输出控制台中,我看到了:

[ Build output of all Release builds ]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705,2008 /nostdlib+ /platform:x64 /errorreport:prompt /warn:4 /define:TRACE;RELEASE;NETCOREAPP1_1 /errorendlocation /preferreduilang:en-US [...] /reference:D:\Workspace\MySolution\Project1\bin\Debug\netstandard1.6\Project1.dll /reference:D:\Workspace\MySolution\Project2\bin\Debug\netstandard1.6\Project2.dll [...]

请注意它实际上是如何使用bin\Debug文件而不是bin\Release文件。

如何在发布时强制Visual Studio使用Release版本而不是过时的Debug版本?

0 个答案:

没有答案