我的项目设置如下:
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决定使用Project1
和Project2
的旧调试版本,而不是新版本。我已将问题追溯到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版本?