Referencing nuget packages in csharp csproj files

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Referencing nuget packages in csharp csproj files

Joern Hauser

Hello,

 

we’re looking into generating our C# projects using CMAKE. We can generate working solution files, but we’re still struggling with dependencies. We would like to manage nuget packages via the nuget.exe command line tool. With the install or restore parameter this deems us a good approach for managing dependencies. However, CMAKE currently only supports the Reference tag in the csproj file. Without an additional HintPath subtag into the package’s folder the reference is not resolved. This HintPath points down the whole path to the DLL of the package, including version etc. So far I have not found a way how to extract this path from nuget.exe and I would not like having to guess it to fill the HintPath tag.

 

Any ideas how to solve this issue?

 

We found that using the new PackageReference tag (new since VS2017) would work fine without a HintPath and would offer complete configuration of dependencies via nuget.

 

So we wondered if CMAKE could support this new PackageReference tag, too, like it does for the Reference tag by means of the VS_DOTNET_REFERENCES? Or is there any way how we could inject the XML into the generated csproj file ourselves from the project’s CMakeLists.txt? Looking into the CMAKE source code, I think supporting the PackageReference tag would basically require going along the lines of the VS_DOTNET_REFERENCES property handling. However, I don’t know if another property like this (e.g. VS_DOTNET_PACKAGEREFERENCES) would be appreciated by the CMAKE team or whether there are better solutions? If such a property were acceptable maybe we could even try to offer a patch for CMAKE.

 

Thank you!

 

Cheers,

Jörn

 

 

 


--

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
Reply | Threaded
Open this post in threaded view
|

Re: Referencing nuget packages in csharp csproj files

Jacob Barrett
Joern,

We too have been trying to find better integration between CMake and NuGet. What we have done is taken advantage of the packages.config file and the nuget.exe command line too. We have a custom target that executes `nuget restore` against the generated solution file. This by default places all the nuget packages in a packages directory under the build directory. It also updates all the references in the generate csproj files to the point to the packages directory. It works pretty good and does a great job of download dependencies when taking the sources to a new machine. 

It would be nice though to have a way to specify the dependencies in the CMake file and have it fetch and explode them like nuget does and generate the correct csproj upfront. 

Here is some snippets from our CMakeLists.txt:

find_program(NUGET nuget)
add_custom_target(nuget-restore 
  COMMAND ${NUGET} restore ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.sln
)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/packages.config ${CMAKE_CURRENT_BINARY_DIR}/packages.config COPYONLY)

set_target_properties( ${PROJECT_NAME} PROPERTIES
  VS_GLOBAL_ROOTNAMESPACE ${PROJECT_NAME}
  VS_GLOBAL_ProjectGuid "{f84e584d-a422-3021-a20c-cec777413cae}"
  VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.5.2"
  VS_DOTNET_REFERENCES "System;System.Xml;System.Web;System.Configuration;System.Xml.Linq"
)

add_dependencies(${PROJECT_NAME} nuget-restore)

-Jake


On Tue, Jan 30, 2018 at 2:02 AM Joern Hauser <[hidden email]> wrote:

Hello,

 

we’re looking into generating our C# projects using CMAKE. We can generate working solution files, but we’re still struggling with dependencies. We would like to manage nuget packages via the nuget.exe command line tool. With the install or restore parameter this deems us a good approach for managing dependencies. However, CMAKE currently only supports the Reference tag in the csproj file. Without an additional HintPath subtag into the package’s folder the reference is not resolved. This HintPath points down the whole path to the DLL of the package, including version etc. So far I have not found a way how to extract this path from nuget.exe and I would not like having to guess it to fill the HintPath tag.

 

Any ideas how to solve this issue?

 

We found that using the new PackageReference tag (new since VS2017) would work fine without a HintPath and would offer complete configuration of dependencies via nuget.

 

So we wondered if CMAKE could support this new PackageReference tag, too, like it does for the Reference tag by means of the VS_DOTNET_REFERENCES? Or is there any way how we could inject the XML into the generated csproj file ourselves from the project’s CMakeLists.txt? Looking into the CMAKE source code, I think supporting the PackageReference tag would basically require going along the lines of the VS_DOTNET_REFERENCES property handling. However, I don’t know if another property like this (e.g. VS_DOTNET_PACKAGEREFERENCES) would be appreciated by the CMAKE team or whether there are better solutions? If such a property were acceptable maybe we could even try to offer a patch for CMAKE.

 

Thank you!

 

Cheers,

Jörn

 

 

 

--

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

--

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