[vcpkg] Add vcpkg item to project settings in Visual Studio
MODIFY
include/vcpkg/vcpkgpaths.h
include/vcpkg/vcpkgpaths.h
@@ -85,6 +85,7 @@ namespace vcpkg
fs::path tools;
fs::path buildsystems;
fs::path buildsystems_msbuild_targets;
+ fs::path buildsystems_msbuild_props;
fs::path vcpkg_dir;
fs::path vcpkg_dir_status_file;

MODIFY
src/vcpkg/commands.integrate.cpp
src/vcpkg/commands.integrate.cpp
namespace vcpkg::Commands::Integrate
{
#if defined(_WIN32)
- static std::string create_appdata_targets_shortcut(const std::string& target_path) noexcept
+ static std::string create_appdata_shortcut(const std::string& target_path) noexcept
{
return Strings::format(R"###(
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
@@ -34,6 +34,7 @@ namespace vcpkg::Commands::Integrate
<PropertyGroup>
<VCLibPackagePath Condition="'$(VCLibPackagePath)' == ''">$(LOCALAPPDATA)\vcpkg\vcpkg.user</VCLibPackagePath>
</PropertyGroup>
+ <Import Condition="'$(VCLibPackagePath)' != '' and Exists('$(VCLibPackagePath).props')" Project="$(VCLibPackagePath).props" />
<Import Condition="'$(VCLibPackagePath)' != '' and Exists('$(VCLibPackagePath).targets')" Project="$(VCLibPackagePath).targets" />
</Project>
)###";
@@ -159,6 +160,14 @@ namespace vcpkg::Commands::Integrate
return LOCAL_APP_DATA / fs::u8path("vcpkg/vcpkg.user.targets");
}
#endif
+#if defined(_WIN32)
+ static fs::path get_appdata_props_path()
+ {
+ static const fs::path LOCAL_APP_DATA =
+ fs::u8path(System::get_environment_variable("LOCALAPPDATA").value_or_exit(VCPKG_LINE_INFO));
+ return LOCAL_APP_DATA / "vcpkg" / "vcpkg.user.props";
+ }
+#endif
static fs::path get_path_txt_path() { return get_user_dir() / "vcpkg.path.txt"; }
@@ -248,7 +257,7 @@ namespace vcpkg::Commands::Integrate
const fs::path appdata_src_path = tmp_dir / "vcpkg.user.targets";
fs.write_contents(appdata_src_path,
- create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.u8string()),
+ create_appdata_shortcut(paths.buildsystems_msbuild_targets.u8string()),
VCPKG_LINE_INFO);
auto appdata_dst_path = get_appdata_targets_path();
@@ -264,6 +273,25 @@ namespace vcpkg::Commands::Integrate
"\n");
Checks::exit_fail(VCPKG_LINE_INFO);
}
+
+ const fs::path appdata_src_path2 = tmp_dir / "vcpkg.user.props";
+ fs.write_contents(appdata_src_path2,
+ create_appdata_shortcut(paths.buildsystems_msbuild_props.u8string()),
+ VCPKG_LINE_INFO);
+ auto appdata_dst_path2 = get_appdata_props_path();
+
+ const auto rc2 = fs.copy_file(appdata_src_path2, appdata_dst_path2, fs::copy_options::overwrite_existing, ec);
+
+ if (!rc2 || ec)
+ {
+ System::print2(System::Color::error,
+ "Error: Failed to copy file: ",
+ appdata_src_path2.u8string(),
+ " -> ",
+ appdata_dst_path2.u8string(),
+ "\n");
+ Checks::exit_fail(VCPKG_LINE_INFO);
+ }
}
#endif
@@ -304,6 +332,11 @@ CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=%s"
was_deleted |= fs.remove(path, ec);
Checks::check_exit(VCPKG_LINE_INFO, !ec, "Error: Unable to remove user-wide integration: %s", ec.message());
+
+ const fs::path path2 = get_appdata_props_path();
+
+ was_deleted |= fs.remove(path2, ec);
+ Checks::check_exit(VCPKG_LINE_INFO, !ec, "Error: Unable to remove user-wide integration: %s", ec.message());
#endif
was_deleted |= fs.remove(get_path_txt_path(), ec);

MODIFY
src/vcpkg/export.cpp
src/vcpkg/export.cpp
@@ -25,7 +25,8 @@ namespace vcpkg::Export
using Install::InstallDir;
static std::string create_nuspec_file_contents(const std::string& raw_exported_dir,
- const std::string& targets_redirect_path,
+ const fs::path& targets_redirect_path,
+ const fs::path& props_redirect_path,
const std::string& nuget_id,
const std::string& nupkg_version)
{
@@ -44,6 +45,7 @@ namespace vcpkg::Export
<file src="@RAW_EXPORTED_DIR@\scripts\**" target="scripts" />
<file src="@RAW_EXPORTED_DIR@\.vcpkg-root" target="" />
<file src="@TARGETS_REDIRECT_PATH@" target="build\native\@NUGET_ID@.targets" />
+ <file src="@PROPS_REDIRECT_PATH@" target="build\native\@NUGET_ID@.props" />
</files>
</package>
)";
@@ -52,8 +54,10 @@ namespace vcpkg::Export
nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@VERSION@", nupkg_version);
nuspec_file_content =
Strings::replace_all(std::move(nuspec_file_content), "@RAW_EXPORTED_DIR@", raw_exported_dir);
- nuspec_file_content =
- Strings::replace_all(std::move(nuspec_file_content), "@TARGETS_REDIRECT_PATH@", targets_redirect_path);
+ nuspec_file_content = Strings::replace_all(
+ std::move(nuspec_file_content), "@TARGETS_REDIRECT_PATH@", targets_redirect_path.u8string());
+ nuspec_file_content = Strings::replace_all(
+ std::move(nuspec_file_content), "@PROPS_REDIRECT_PATH@", props_redirect_path.u8string());
return nuspec_file_content;
}
@@ -136,18 +140,23 @@ namespace vcpkg::Export
Files::Filesystem& fs = paths.get_filesystem();
const fs::path& nuget_exe = paths.get_tool_exe(Tools::NUGET);
+ std::error_code ec;
+ fs.create_directories(paths.buildsystems / "tmp", ec);
+
// This file will be placed in "build\native" in the nuget package. Therefore, go up two dirs.
const std::string targets_redirect_content =
create_targets_redirect("$(MSBuildThisFileDirectory)../../scripts/buildsystems/msbuild/vcpkg.targets");
const fs::path targets_redirect = paths.buildsystems / "tmp" / "vcpkg.export.nuget.targets";
-
- std::error_code ec;
- fs.create_directories(paths.buildsystems / "tmp", ec);
-
fs.write_contents(targets_redirect, targets_redirect_content, VCPKG_LINE_INFO);
- const std::string nuspec_file_content =
- create_nuspec_file_contents(raw_exported_dir.string(), targets_redirect.string(), nuget_id, nuget_version);
+ // This file will be placed in "build\native" in the nuget package. Therefore, go up two dirs.
+ const std::string props_redirect_content =
+ create_targets_redirect("$(MSBuildThisFileDirectory)../../scripts/buildsystems/msbuild/vcpkg.props");
+ const fs::path props_redirect = paths.buildsystems / "tmp" / "vcpkg.export.nuget.props";
+ fs.write_contents(props_redirect, props_redirect_content, VCPKG_LINE_INFO);
+
+ const std::string nuspec_file_content = create_nuspec_file_contents(
+ raw_exported_dir.string(), targets_redirect, props_redirect, nuget_id, nuget_version);
const fs::path nuspec_file_path = paths.buildsystems / "tmp" / "vcpkg.export.nuspec";
fs.write_contents(nuspec_file_path, nuspec_file_content, VCPKG_LINE_INFO);
@@ -235,6 +244,8 @@ namespace vcpkg::Export
{".vcpkg-root"},
{fs::path{"scripts"} / "buildsystems" / "msbuild" / "applocal.ps1"},
{fs::path{"scripts"} / "buildsystems" / "msbuild" / "vcpkg.targets"},
+ {fs::path{"scripts"} / "buildsystems" / "msbuild" / "vcpkg.props"},
+ {fs::path{"scripts"} / "buildsystems" / "msbuild" / "vcpkg-general.xml"},
{fs::path{"scripts"} / "buildsystems" / "vcpkg.cmake"},
{fs::path{"scripts"} / "cmake" / "vcpkg_get_windows_sdk.cmake"},
};
@@ -303,9 +314,6 @@ namespace vcpkg::Export
static constexpr StringLiteral OPTION_PREFAB_ENABLE_MAVEN = "--prefab-maven";
static constexpr StringLiteral OPTION_PREFAB_ENABLE_DEBUG = "--prefab-debug";
-
-
-
static constexpr std::array<CommandSwitch, 11> EXPORT_SWITCHES = {{
{OPTION_DRY_RUN, "Do not actually export"},
{OPTION_RAW, "Export to an uncompressed directory"},
@@ -386,9 +394,11 @@ namespace vcpkg::Export
});
}
- if (!ret.raw && !ret.nuget && !ret.ifw && !ret.zip && !ret.seven_zip && !ret.dry_run && !ret.chocolatey && !ret.prefab)
+ if (!ret.raw && !ret.nuget && !ret.ifw && !ret.zip && !ret.seven_zip && !ret.dry_run && !ret.chocolatey &&
+ !ret.prefab)
{
- System::print2(System::Color::error,
+ System::print2(
+ System::Color::error,
"Must provide at least one export type: --raw --nuget --ifw --zip --7zip --chocolatey --prefab\n");
System::print2(COMMAND_STRUCTURE.example_text);
Checks::exit_fail(VCPKG_LINE_INFO);
@@ -638,7 +648,8 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
Chocolatey::do_export(export_plan, paths, opts.chocolatey_options);
}
- if(opts.prefab){
+ if (opts.prefab)
+ {
Prefab::do_export(export_plan, paths, opts.prefab_options, default_triplet);
}

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
@@ -117,7 +117,9 @@ namespace vcpkg
tools = downloads / fs::u8path("tools");
buildsystems = scripts / fs::u8path("buildsystems");
- buildsystems_msbuild_targets = buildsystems / fs::u8path("msbuild") / fs::u8path("vcpkg.targets");
+ const auto msbuildDirectory = buildsystems / fs::u8path("msbuild");
+ buildsystems_msbuild_targets = msbuildDirectory / fs::u8path("vcpkg.targets");
+ buildsystems_msbuild_props = msbuildDirectory / fs::u8path("vcpkg.props");
vcpkg_dir = installed / fs::u8path("vcpkg");
vcpkg_dir_status_file = vcpkg_dir / fs::u8path("status");

[vcpkg] Add vcpkg item to project settings in Visual Studio (#4361)

Co-authored-by: Curtis J Bezault <curtbezault@gmail.com>
Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>
Co-authored-by: Robert Schumacher <roschuma@microsoft.com>