c# - .NET Core .csproj 输出路径无法正常工作

标签 c# .net msbuild .net-core asp.net-core-1.0

我正在使用 Visual Studio 14 (VS 2015) Update 3,我想构建一个基于 .Net Core 1 的 REST API,使用 Kestrel 作为服务器。

我希望能够使用 .csproj 而不是旧的 .xproj 以便像在其他项目中一样使用 MSBuild。为此,我使用了 tutorial they have .

问题是,当我将“OutputPath”定义为“bin\Debug”(例如,对于 Debug模式)时,Visual Studio 构建项目并将构建结果设置为“bin\Debug\\bin\Debug\netcoreapp1. 0\win7-x64".

如果我使用 .xproj 并构建,结果将存储在“bin\Debug\netcoreapp1.0”中,这是预期的行为。

发生了什么事?

.csproj:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    <BaseNuGetRuntimeIdentifier>win7</BaseNuGetRuntimeIdentifier>
    <TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
    <NoStdLib>true</NoStdLib>
    <NoWarn>$(NoWarn);1701</NoWarn>
    <ProjectGuid>{D21ABA46-65F9-4B47-882C-F9C0765052DD}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MyAPP</RootNamespace>
    <AssemblyName>MyAPP</AssemblyName>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>x64</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <IntermediateOutputPath>.\obj\Debug</IntermediateOutputPath>
    <OutputPath>.\bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>x64</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>.\bin\Release</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="src\**\*.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="project.json" />
    <None Include="appsettings.json" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <PropertyGroup>
    <!-- We don't use any of MSBuild's resolution logic for resolving the framework, so just set these two
            properties to any folder that exists to skip the GetReferenceAssemblyPaths task (not target) and
            to prevent it from outputting a warning (MSB3644).
        -->
    <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory)</_TargetFrameworkDirectories>
    <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>
    <!-- MSBuild thinks all EXEs need binding redirects, not so for CoreCLR! -->
    <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
    <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
    <!-- Set up debug options to run with host, and to use the CoreCLR debug engine -->
    <StartAction>Program</StartAction>
    <StartProgram>$(TargetDir)</StartProgram>
    <DebugEngines>{2E36F1D4-B23C-435D-AB41-18E608940038}</DebugEngines>
  </PropertyGroup>
</Project>

项目.json:

{
  "version": "1.0.0",

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "build"
    },
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
  },

  "runtimes": {
    "win7-x64": {},
    "ubuntu.14.04-x64": {},
    "osx.10.10-x64": {}
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [ "dnxcore50", "portable-net452" ]
    }
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish --publish-folder ./bin" ]
  }
}

最佳答案

使用 <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

关于c# - .NET Core .csproj 输出路径无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40426396/

相关文章:

c++ - 让 MSBuild 编译具有 Win32 和 Win64 平台依赖项的项目

c# - 使用 VS2012 在 C# 上进行错误的 float 转换

c# - 如何安全地附加到 ProcessStartInfo.EnvironmentVariables ["PATH"]

c# - C# 中字符串的正则表达式

c# - 如何在 C# 中处理带有持续时间的实际时间?

c++ - 如何配置 Jenkins 以使用 Qt 构建解决方案?

msbuild - 在 MSBuild 中将程序集版本号指定为命令行参数

C#属性和ref参数,为什么不加糖?

c# - Entity Framework 在循环集合中返回 NULL

.net - 设置符号服务器可以给我带来什么?