c# - 作为子项的 DotNet Core .csproj 代码文件

标签 c# msbuild .net-core csproj

我正在将旧的 .NET Framework csproj 迁移到 dotnet core。与此等效的 dotnet 核心是什么:

<Compile Include="ServiceHost.Designer.cs">
  <DependentUpon>ServiceHost.cs</DependentUpon>
</Compile>

我试过:

<ItemGroup>
    <Compile Include="ServiceHost.Designer.cs">
        <DependentUpon>ServiceHost.cs</DependentUpon>
    </Compile>
</ItemGroup>

但是我得到了这个错误:

Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'ProjectInstaller.Designer.cs'; 'ServiceHost.Designer.cs' TestWindowsService C:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets

最佳答案

由于项目默认包含,如果您只想修改需要此更新的项目而不列出每个 cs,则需要使用 Update 而不是 Include单独归档:

<ItemGroup>
    <Compile Update="ServiceHost.Designer.cs">
        <DependentUpon>ServiceHost.cs</DependentUpon>
    </Compile>
</ItemGroup>

关于c# - 作为子项的 DotNet Core .csproj 代码文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48424567/

相关文章:

msbuild - CSC 错误 CS0006 : Metadata file 'SonarAnalyzer.dll' could not be found

.net-core - 包含 dotnet core 应用程序的运行时文件夹

c# - Gmail api 与 .Net 客户端库 : Missing draft message [400]

c# - 如何使用 GraphServiceClient Microsoft Graph API 获取 MimeContent

c# - 如何在 .NET Standard 2.0 库项目中将版本附加到程序集输出文件名

.net - 如何根据开发人员的操作系统架构在 Visual Studio 中复制文件?

c# - 如何在.net core WebApi 上获取请求字符串

asp.net-core - .NET Core 2、DI、配置文件

c# - Azure 网络作业 : C# - The Autodiscover service couldn't be located error

c# - SetProfile 上的 Mediarecorder IllegalStateException