Я автоматически генерирую решение Visual Studio с помощью CMake, структура выглядит следующим образом:
/src
CMakeLists.txt
SomeSource.cs
/build << contents of this folder generated by CMake
GeneratedCode.cs
MyProject.sln
MyProjectNET.csharp
<other files by CMake>
Проблема в том, что когда я открываю решение в Visual Studio, проект C # содержит все в папке /build
, включая выходные каталоги и так далее. Я проверил файл .csproj
, чтобы убедиться, что CMake сгенерировал проект, чтобы все эти файлы были явно включены, но это не так.
Теперь это будет только неудобство. Однако, как вы видите, у меня есть GeneratedCode.cs
в каталоге /build
. Этот код сгенерирован CMake. Поскольку CMake знает, что он является частью проекта, он явно добавляет ссылку при генерации MyProjectNET.csharp
. Поведение, которое я наблюдаю сейчас, заключается в том, что при открытии GeneratedCode.cs
в Visual Studio редактор подчеркивает почти все красным, говоря, что это «неоднозначная ссылка», и перечисляя один и тот же класс, расположенный в GeneratedCode.cs
, в два раза больше возможного источника. Это делает практически невозможным обнаружение реальных ошибок в коде.
Интересно, что компиляция кода работает. Я только получаю предупреждение, что компилятор получил один и тот же файл дважды при вводе. Тем не менее я хочу избавиться от этого поведения для более продуктивной работы с кодом.
Итак, причина моей проблемы в том, что мой проект автоматически содержит все файлы в папке /build
, а затем явным образом файл GeneratedCode.cs
, что смущает Visual Studio. Почему все файлы в моем проекте? Я предполагаю, что это не нормальное поведение, потому что я не вижу, что это происходит для проектов C ++ и для другого проекта C #, который не генерируется CMake. Я предполагаю, что CMake сгенерировал некоторые странные настройки в файле .csproj
, но я не могу найти ничего, что может иметь какое-либо отношение к моей проблеме, в файле проекта. Какой параметр вызовет такое поведение?
Редактировать: версия VS - 2017, версия 15.9.9. В надежде, что это подходит, вот фактический файл проекта:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>{0AE1D52A-C2A2-35E1-914D-92101FC2A02F}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<Keyword>Win32Proj</Keyword>
<Platform>x64</Platform>
<ProjectName>libheroes.NET</ProjectName>
<VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Authors>Felix Krause</Authors>
<LangVersion>7.2</LangVersion>
<PackageId>Libheroes.NET</PackageId>
<RootNamespace>Heroes</RootNamespace>
<Version>0.1.0</Version>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFramework>netstandard2.0</TargetFramework></PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<DebugSymbols>true</DebugSymbols>
<DefineDebug>true</DefineDebug>
<OutputPath>D:\Projects\libheroes\bindings\csharp\cmake-vs\Debug\</OutputPath>
<PlatformToolset>v141</PlatformToolset>
<AssemblyName>libheroes.NET</AssemblyName>
<AdditionalOptions>/langversion:7.2</AdditionalOptions>
<DebugType>full</DebugType>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<Optimize>false</Optimize>
<WarningLevel>3</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<OutputPath>D:\Projects\libheroes\bindings\csharp\cmake-vs\Release\</OutputPath>
<PlatformToolset>v141</PlatformToolset>
<AssemblyName>libheroes.NET</AssemblyName>
<AdditionalOptions>/langversion:7.2</AdditionalOptions>
<DebugType>none</DebugType>
<DefineConstants />
<ErrorReport>queue</ErrorReport>
<Optimize>true</Optimize>
<WarningLevel>1</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|x64'" Label="Configuration">
<OutputPath>D:\Projects\libheroes\bindings\csharp\cmake-vs\MinSizeRel\</OutputPath>
<PlatformToolset>v141</PlatformToolset>
<AssemblyName>libheroes.NET</AssemblyName>
<AdditionalOptions>/langversion:7.2</AdditionalOptions>
<DebugType>none</DebugType>
<DefineConstants />
<Optimize>true</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|x64'" Label="Configuration">
<DebugSymbols>true</DebugSymbols>
<DefineDebug>true</DefineDebug>
<OutputPath>D:\Projects\libheroes\bindings\csharp\cmake-vs\RelWithDebInfo\</OutputPath>
<PlatformToolset>v141</PlatformToolset>
<AssemblyName>libheroes.NET</AssemblyName>
<AdditionalOptions>/langversion:7.2</AdditionalOptions>
<DebugType>full</DebugType>
<DefineConstants />
<Optimize>false</Optimize>
</PropertyGroup>
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.CSharp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.CSharp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemGroup>
<None Include="D:\Projects\libheroes\bindings\csharp\CMakeLists.txt">
<Link>CMakeLists.txt</Link>
</None>
</ItemGroup>
<Target Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Name="CustomCommand_Debug_a636c07f1d51cd46229efc4bacc41a89" Inputs="D:/Projects/libheroes/bindings/csharp/CMakeLists.txt;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCSharpCompiler.cmake.in;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCSharpInformation.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCompilerIdDetection.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCSharpCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCompilerId.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeGenericSystem.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeInitializeConfigs.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeSystemSpecificInformation.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeSystemSpecificInitialize.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeTestCSharpCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeTestCompilerCommon.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CompilerId\VS-10.csproj.in;C:\Program Files\CMake\share\cmake-3.14\Modules\Platform\Windows.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\Platform\WindowsPaths.cmake;D:\Projects\libheroes\bindings\csharp\CMakeLists.txt;D:\Projects\libheroes\bindings\csharp\LibHeroes.NET.targets;D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\3.14.0\CMakeCSharpCompiler.cmake;D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\3.14.0\CMakeSystem.cmake;D:\Projects\libheroes\bindings\csharp\CMakeLists.txt" Outputs="D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\generate.stamp">
<Exec Command="echo Building Custom Rule D:/Projects/libheroes/bindings/csharp/CMakeLists.txt" />
<Exec Command="setlocal
"C:\Program Files\CMake\bin\cmake.exe" -SD:/Projects/libheroes/bindings/csharp -BD:/Projects/libheroes/bindings/csharp/cmake-vs --check-stamp-file D:/Projects/libheroes/bindings/csharp/cmake-vs/CMakeFiles/generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd" />
</Target>
<Target Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Name="CustomCommand_Release_a636c07f1d51cd46229efc4bacc41a89" Inputs="D:/Projects/libheroes/bindings/csharp/CMakeLists.txt;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCSharpCompiler.cmake.in;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCSharpInformation.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCompilerIdDetection.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCSharpCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCompilerId.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeGenericSystem.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeInitializeConfigs.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeSystemSpecificInformation.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeSystemSpecificInitialize.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeTestCSharpCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeTestCompilerCommon.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CompilerId\VS-10.csproj.in;C:\Program Files\CMake\share\cmake-3.14\Modules\Platform\Windows.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\Platform\WindowsPaths.cmake;D:\Projects\libheroes\bindings\csharp\CMakeLists.txt;D:\Projects\libheroes\bindings\csharp\LibHeroes.NET.targets;D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\3.14.0\CMakeCSharpCompiler.cmake;D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\3.14.0\CMakeSystem.cmake;D:\Projects\libheroes\bindings\csharp\CMakeLists.txt" Outputs="D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\generate.stamp">
<Exec Command="echo Building Custom Rule D:/Projects/libheroes/bindings/csharp/CMakeLists.txt" />
<Exec Command="setlocal
"C:\Program Files\CMake\bin\cmake.exe" -SD:/Projects/libheroes/bindings/csharp -BD:/Projects/libheroes/bindings/csharp/cmake-vs --check-stamp-file D:/Projects/libheroes/bindings/csharp/cmake-vs/CMakeFiles/generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd" />
</Target>
<Target Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|x64'" Name="CustomCommand_MinSizeRel_a636c07f1d51cd46229efc4bacc41a89" Inputs="D:/Projects/libheroes/bindings/csharp/CMakeLists.txt;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCSharpCompiler.cmake.in;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCSharpInformation.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCompilerIdDetection.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCSharpCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCompilerId.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeGenericSystem.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeInitializeConfigs.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeSystemSpecificInformation.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeSystemSpecificInitialize.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeTestCSharpCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeTestCompilerCommon.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CompilerId\VS-10.csproj.in;C:\Program Files\CMake\share\cmake-3.14\Modules\Platform\Windows.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\Platform\WindowsPaths.cmake;D:\Projects\libheroes\bindings\csharp\CMakeLists.txt;D:\Projects\libheroes\bindings\csharp\LibHeroes.NET.targets;D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\3.14.0\CMakeCSharpCompiler.cmake;D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\3.14.0\CMakeSystem.cmake;D:\Projects\libheroes\bindings\csharp\CMakeLists.txt" Outputs="D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\generate.stamp">
<Exec Command="echo Building Custom Rule D:/Projects/libheroes/bindings/csharp/CMakeLists.txt" />
<Exec Command="setlocal
"C:\Program Files\CMake\bin\cmake.exe" -SD:/Projects/libheroes/bindings/csharp -BD:/Projects/libheroes/bindings/csharp/cmake-vs --check-stamp-file D:/Projects/libheroes/bindings/csharp/cmake-vs/CMakeFiles/generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd" />
</Target>
<Target Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|x64'" Name="CustomCommand_RelWithDebInfo_a636c07f1d51cd46229efc4bacc41a89" Inputs="D:/Projects/libheroes/bindings/csharp/CMakeLists.txt;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCSharpCompiler.cmake.in;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCSharpInformation.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeCompilerIdDetection.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCSharpCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeDetermineCompilerId.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeGenericSystem.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeInitializeConfigs.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeSystemSpecificInformation.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeSystemSpecificInitialize.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeTestCSharpCompiler.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CMakeTestCompilerCommon.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\CompilerId\VS-10.csproj.in;C:\Program Files\CMake\share\cmake-3.14\Modules\Platform\Windows.cmake;C:\Program Files\CMake\share\cmake-3.14\Modules\Platform\WindowsPaths.cmake;D:\Projects\libheroes\bindings\csharp\CMakeLists.txt;D:\Projects\libheroes\bindings\csharp\LibHeroes.NET.targets;D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\3.14.0\CMakeCSharpCompiler.cmake;D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\3.14.0\CMakeSystem.cmake;D:\Projects\libheroes\bindings\csharp\CMakeLists.txt" Outputs="D:\Projects\libheroes\bindings\csharp\cmake-vs\CMakeFiles\generate.stamp">
<Exec Command="echo Building Custom Rule D:/Projects/libheroes/bindings/csharp/CMakeLists.txt" />
<Exec Command="setlocal
"C:\Program Files\CMake\bin\cmake.exe" -SD:/Projects/libheroes/bindings/csharp -BD:/Projects/libheroes/bindings/csharp/cmake-vs --check-stamp-file D:/Projects/libheroes/bindings/csharp/cmake-vs/CMakeFiles/generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd" />
</Target>
<ItemGroup>
<Compile Include="D:\Projects\libheroes\bindings\csharp\cmake-vs\LibHeroes.cs" />
<Compile Include="D:\Projects\libheroes\bindings\csharp\Marshaling.cs">
<Link>Marshaling.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="D:\Projects\libheroes\bindings\csharp\cmake-vs\ZERO_CHECK.vcxproj">
<Project>{C0C9F6B6-CF04-32B9-BDB5-A1812B10331E}</Project>
<Name>ZERO_CHECK</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</ProjectReference>
<ProjectReference Include="D:\Projects\libheroes\bindings\csharp\cmake-vs\build\libheroes.vcxproj">
<Project>{E8B13004-193F-393B-90DB-A41070EDBD99}</Project>
<Name>libheroes</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</ProjectReference>
</ItemGroup>
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'MinSizeRel'">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'RelWithDebInfo'">
</PropertyGroup>
<PropertyGroup>
<BuildDependsOn>
CustomCommand_Debug_a636c07f1d51cd46229efc4bacc41a89;
CustomCommand_MinSizeRel_a636c07f1d51cd46229efc4bacc41a89;
CustomCommand_RelWithDebInfo_a636c07f1d51cd46229efc4bacc41a89;
CustomCommand_Release_a636c07f1d51cd46229efc4bacc41a89;
$(BuildDependsOn)
</BuildDependsOn>
</PropertyGroup>
<ItemGroup><Content Include="build\Libheroes.NET.targets"><Pack>true</Pack><PackagePath>\build\</PackagePath></Content><Content Include="build\$(Configuration)\yaml.dll"><Pack>true</Pack><PackagePath>\build\</PackagePath></Content><Content Include="build\$(Configuration)\libheroes.dll"><Pack>true</Pack><PackagePath>\build\</PackagePath></Content></ItemGroup></Project>