diff --git a/templates/vsprojects/grpc/packages.config.template b/templates/vsprojects/grpc/packages.config.template
index 04baa390804832ae290c2b6aba4bbb080a441cde..66ac90eb0851b8aa9f0504bf38ba666585d6e9f6 100644
--- a/templates/vsprojects/grpc/packages.config.template
+++ b/templates/vsprojects/grpc/packages.config.template
@@ -1,7 +1,2 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-  <package id="openssl" version="1.0.2.1" targetFramework="Native" />
-  <package id="openssl.redist" version="1.0.2.1" targetFramework="Native" />
-  <package id="zlib" version="1.2.8.7" targetFramework="Native" />
-  <package id="zlib.redist" version="1.2.8.7" targetFramework="Native" />
-</packages>
\ No newline at end of file
+<%namespace file="../packages.include" import="gen_packages_config"/>\
+${gen_packages_config(['openssl','zlib'])}
\ No newline at end of file
diff --git a/templates/vsprojects/grpc_csharp_ext/packages.config.template b/templates/vsprojects/grpc_csharp_ext/packages.config.template
index 04baa390804832ae290c2b6aba4bbb080a441cde..4953b6451c908093105673027ab39c8243360cd1 100644
--- a/templates/vsprojects/grpc_csharp_ext/packages.config.template
+++ b/templates/vsprojects/grpc_csharp_ext/packages.config.template
@@ -1,7 +1,2 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-  <package id="openssl" version="1.0.2.1" targetFramework="Native" />
-  <package id="openssl.redist" version="1.0.2.1" targetFramework="Native" />
-  <package id="zlib" version="1.2.8.7" targetFramework="Native" />
-  <package id="zlib.redist" version="1.2.8.7" targetFramework="Native" />
-</packages>
\ No newline at end of file
+<%namespace file="../packages.include" import="gen_packages_config"/>\
+${gen_packages_config(['openssl','zlib'])}
\ No newline at end of file
diff --git a/templates/vsprojects/grpc_unsecure/packages.config.template b/templates/vsprojects/grpc_unsecure/packages.config.template
index b0829dd294ef8ff12db197ca8412721d0993d7b6..1337b5df2b7bae9af6c1f351b740a1741e2f6cf3 100644
--- a/templates/vsprojects/grpc_unsecure/packages.config.template
+++ b/templates/vsprojects/grpc_unsecure/packages.config.template
@@ -1,5 +1,2 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-  <package id="zlib" version="1.2.8.7" targetFramework="Native" />
-  <package id="zlib.redist" version="1.2.8.7" targetFramework="Native" />
-</packages>
\ No newline at end of file
+<%namespace file="../packages.include" import="gen_packages_config"/>\
+${gen_packages_config(['zlib'])}
\ No newline at end of file
diff --git a/templates/vsprojects/packages.include b/templates/vsprojects/packages.include
new file mode 100644
index 0000000000000000000000000000000000000000..a2887846074885727c3caea4d3030be2fbbffc83
--- /dev/null
+++ b/templates/vsprojects/packages.include
@@ -0,0 +1,13 @@
+<%def name="gen_packages_config(packages)">\
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  % if 'openssl' in packages:
+  <package id="openssl" version="1.0.2.1" targetFramework="Native" />
+  <package id="openssl.redist" version="1.0.2.1" targetFramework="Native" />
+  % endif
+  % if 'zlib' in packages:
+  <package id="zlib" version="1.2.8.7" targetFramework="Native" />
+  <package id="zlib.redist" version="1.2.8.7" targetFramework="Native" />
+  % endif
+</packages>
+</%def>\
\ No newline at end of file
diff --git a/templates/vsprojects/vcxproj_defs.include b/templates/vsprojects/vcxproj_defs.include
index 94ffbdbb7232ff7a587d76777440dda125498d3f..12680d407c604411db9b652fc0918b5862492399 100644
--- a/templates/vsprojects/vcxproj_defs.include
+++ b/templates/vsprojects/vcxproj_defs.include
@@ -1,3 +1,4 @@
+<%namespace file="packages.include" import="gen_packages_config"/>\
 <%def name="get_repo_root()">..\..</%def>\
 <%def name="to_windows_path(path)">${path.replace('/','\\')}</%def>\
 <%def name="get_subsystem(is_library)">${'Windows' if is_library else 'Console'}</%def>\