Discussion:
[cmake-developers] Link element in C# project causing issues with binary dir
Robert Dailey
2018-06-29 20:08:00 UTC
Permalink
When I use configure_file() to generate AssemblyInfo.cs, which I allow
to go to the CMAKE_CURRENT_BINARY_DIR, Visual Studio 2017 reports:

Warning The file
'E:\code\layout-composer-build\Properties\AssemblyInfo.cs' could not
be added to the project. Cannot add a link to the file
E:\code\layout-composer-build\Properties\AssemblyInfo.cs. This file is
within the project directory tree.

When I define a target using C# language, it adds this for files under
the same directory as the generated CSPROJ file:

<Compile Include="E:\code\layout-composer-build\Properties\AssemblyInfo.cs">
<Link>build\Properties\AssemblyInfo.cs</Link>
</Compile>

The CSPROJ file is located: E:\code\layout-composer-build\LayoutComposer.csproj

Is there a way to make the <Link> element not needed in this scenario?
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers
Robert Dailey
2018-06-29 20:12:46 UTC
Permalink
According to the code, the logic is wrong:

void cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
cmSourceFile const* sf, std::string& link)
{
std::string f = sf->GetFullPath();
if (!this->InSourceBuild) {
const std::string stripFromPath =
this->Makefile->GetCurrentSourceDirectory();
if (f.find(stripFromPath) != std::string::npos) {
link = f.substr(stripFromPath.length() + 1);
if (const char* l = sf->GetProperty("VS_CSHARP_Link")) {
link = l;
}
ConvertToWindowsSlash(link);
}
}
}


It's checking if the whole binary dir is rooted where source dir is,
instead it should be checking each file to see if they are descendents
of CMAKE_BINARY_DIR, and if so, use the <Link>, otherwise don't use
it. This allows <Link> to be variable between files in the project.

Does anyone know if there's already a function in CMake for checking
if a file is in the CMAKE_BINARY_DIR? Or do I have to write my own
code for that check?
Post by Robert Dailey
When I use configure_file() to generate AssemblyInfo.cs, which I allow
Warning The file
'E:\code\layout-composer-build\Properties\AssemblyInfo.cs' could not
be added to the project. Cannot add a link to the file
E:\code\layout-composer-build\Properties\AssemblyInfo.cs. This file is
within the project directory tree.
When I define a target using C# language, it adds this for files under
<Compile Include="E:\code\layout-composer-build\Properties\AssemblyInfo.cs">
<Link>build\Properties\AssemblyInfo.cs</Link>
</Compile>
The CSPROJ file is located: E:\code\layout-composer-build\LayoutComposer.csproj
Is there a way to make the <Link> element not needed in this scenario?
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers
David Cole via cmake-developers
2018-06-29 20:37:33 UTC
Permalink
The code looks wrong like this, too:

You shouldn't strip the source directory from the path of the file
name unless the character after the source directory is "/" or "\\",
should you? If the thing you're trying to end up with is a path name
to the file under the source directory, then this is incorrect in this
case.

I'm guessing you have "layout-composer" and "layout-composer-build" as
sibling directories of each other?
Post by Robert Dailey
void cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
cmSourceFile const* sf, std::string& link)
{
std::string f = sf->GetFullPath();
if (!this->InSourceBuild) {
const std::string stripFromPath =
this->Makefile->GetCurrentSourceDirectory();
if (f.find(stripFromPath) != std::string::npos) {
link = f.substr(stripFromPath.length() + 1);
if (const char* l = sf->GetProperty("VS_CSHARP_Link")) {
link = l;
}
ConvertToWindowsSlash(link);
}
}
}
It's checking if the whole binary dir is rooted where source dir is,
instead it should be checking each file to see if they are descendents
of CMAKE_BINARY_DIR, and if so, use the <Link>, otherwise don't use
it. This allows <Link> to be variable between files in the project.
Does anyone know if there's already a function in CMake for checking
if a file is in the CMAKE_BINARY_DIR? Or do I have to write my own
code for that check?
Post by Robert Dailey
When I use configure_file() to generate AssemblyInfo.cs, which I allow
Warning The file
'E:\code\layout-composer-build\Properties\AssemblyInfo.cs' could not
be added to the project. Cannot add a link to the file
E:\code\layout-composer-build\Properties\AssemblyInfo.cs. This file is
within the project directory tree.
When I define a target using C# language, it adds this for files under
<Compile Include="E:\code\layout-composer-build\Properties\AssemblyInfo.cs">
<Link>build\Properties\AssemblyInfo.cs</Link>
</Compile>
The CSPROJ file is located: E:\code\layout-composer-build\LayoutComposer.csproj
Is there a way to make the <Link> element not needed in this scenario?
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
https://cmake.org/mailman/listinfo/cmake-developers
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers
Robert Dailey
2018-06-29 20:48:41 UTC
Permalink
Submitted a fix here:
https://gitlab.kitware.com/cmake/cmake/merge_requests/2177

David: I think the source dir is stripped because that path is
effectively the same as source_group() command. It's a path relative
to the root of the solution explorer panel. That's a big assumption, I
honestly don't know what the inner workings of the CSPROJ file are.

Yes, they are sibling directories
Post by David Cole via cmake-developers
You shouldn't strip the source directory from the path of the file
name unless the character after the source directory is "/" or "\\",
should you? If the thing you're trying to end up with is a path name
to the file under the source directory, then this is incorrect in this
case.
I'm guessing you have "layout-composer" and "layout-composer-build" as
sibling directories of each other?
Post by Robert Dailey
void cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
cmSourceFile const* sf, std::string& link)
{
std::string f = sf->GetFullPath();
if (!this->InSourceBuild) {
const std::string stripFromPath =
this->Makefile->GetCurrentSourceDirectory();
if (f.find(stripFromPath) != std::string::npos) {
link = f.substr(stripFromPath.length() + 1);
if (const char* l = sf->GetProperty("VS_CSHARP_Link")) {
link = l;
}
ConvertToWindowsSlash(link);
}
}
}
It's checking if the whole binary dir is rooted where source dir is,
instead it should be checking each file to see if they are descendents
of CMAKE_BINARY_DIR, and if so, use the <Link>, otherwise don't use
it. This allows <Link> to be variable between files in the project.
Does anyone know if there's already a function in CMake for checking
if a file is in the CMAKE_BINARY_DIR? Or do I have to write my own
code for that check?
Post by Robert Dailey
When I use configure_file() to generate AssemblyInfo.cs, which I allow
Warning The file
'E:\code\layout-composer-build\Properties\AssemblyInfo.cs' could not
be added to the project. Cannot add a link to the file
E:\code\layout-composer-build\Properties\AssemblyInfo.cs. This file is
within the project directory tree.
When I define a target using C# language, it adds this for files under
<Compile Include="E:\code\layout-composer-build\Properties\AssemblyInfo.cs">
<Link>build\Properties\AssemblyInfo.cs</Link>
</Compile>
The CSPROJ file is located: E:\code\layout-composer-build\LayoutComposer.csproj
Is there a way to make the <Link> element not needed in this scenario?
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
https://cmake.org/mailman/listinfo/cmake-developers
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers
Loading...