├── .gitignore ├── CppWithNuGetPackageReference.sln ├── CppWithNuGetPackageReference ├── CppWithNuGetPackageReference.cpp ├── CppWithNuGetPackageReference.vcxproj ├── CppWithNuGetPackageReference.vcxproj.filters ├── pch.cpp └── pch.h ├── Directory.Build.props ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /CppWithNuGetPackageReference.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.329 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppWithNuGetPackageReference", "CppWithNuGetPackageReference\CppWithNuGetPackageReference.vcxproj", "{F88D9F1D-3C23-410A-B1E6-7971382FCF51}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{35F4AEE3-5012-4B49-BA23-3CCAB20F265B}" 9 | ProjectSection(SolutionItems) = preProject 10 | Directory.Build.props = Directory.Build.props 11 | LICENSE = LICENSE 12 | README.md = README.md 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|x64 = Debug|x64 18 | Debug|x86 = Debug|x86 19 | Release|x64 = Release|x64 20 | Release|x86 = Release|x86 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {F88D9F1D-3C23-410A-B1E6-7971382FCF51}.Debug|x64.ActiveCfg = Debug|x64 24 | {F88D9F1D-3C23-410A-B1E6-7971382FCF51}.Debug|x64.Build.0 = Debug|x64 25 | {F88D9F1D-3C23-410A-B1E6-7971382FCF51}.Debug|x86.ActiveCfg = Debug|Win32 26 | {F88D9F1D-3C23-410A-B1E6-7971382FCF51}.Debug|x86.Build.0 = Debug|Win32 27 | {F88D9F1D-3C23-410A-B1E6-7971382FCF51}.Release|x64.ActiveCfg = Release|x64 28 | {F88D9F1D-3C23-410A-B1E6-7971382FCF51}.Release|x64.Build.0 = Release|x64 29 | {F88D9F1D-3C23-410A-B1E6-7971382FCF51}.Release|x86.ActiveCfg = Release|Win32 30 | {F88D9F1D-3C23-410A-B1E6-7971382FCF51}.Release|x86.Build.0 = Release|Win32 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | GlobalSection(ExtensibilityGlobals) = postSolution 36 | SolutionGuid = {68983C2C-907D-4253-BCED-8FDB7AAC1B1F} 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /CppWithNuGetPackageReference/CppWithNuGetPackageReference.cpp: -------------------------------------------------------------------------------- 1 | // CppWithNuGetPackageReference.cpp : This file contains the 'main' function. Program execution begins and ends there. 2 | // 3 | 4 | #include "pch.h" 5 | #include 6 | 7 | int main() 8 | { 9 | std::cout << "Hello World!\n"; 10 | } 11 | 12 | // Run program: Ctrl + F5 or Debug > Start Without Debugging menu 13 | // Debug program: F5 or Debug > Start Debugging menu 14 | 15 | // Tips for Getting Started: 16 | // 1. Use the Solution Explorer window to add/manage files 17 | // 2. Use the Team Explorer window to connect to source control 18 | // 3. Use the Output window to see build output and other messages 19 | // 4. Use the Error List window to view errors 20 | // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project 21 | // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file 22 | -------------------------------------------------------------------------------- /CppWithNuGetPackageReference/CppWithNuGetPackageReference.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {F88D9F1D-3C23-410A-B1E6-7971382FCF51} 24 | Win32Proj 25 | CppWithNuGetPackageReference 26 | 10.0.17763.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v141 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v141 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v141 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v141 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | true 78 | 79 | 80 | false 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Use 88 | Level3 89 | Disabled 90 | true 91 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 92 | true 93 | pch.h 94 | 95 | 96 | Console 97 | true 98 | 99 | 100 | 101 | 102 | Use 103 | Level3 104 | Disabled 105 | true 106 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 107 | true 108 | pch.h 109 | 110 | 111 | Console 112 | true 113 | 114 | 115 | 116 | 117 | Use 118 | Level3 119 | MaxSpeed 120 | true 121 | true 122 | true 123 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | pch.h 126 | 127 | 128 | Console 129 | true 130 | true 131 | true 132 | 133 | 134 | 135 | 136 | Use 137 | Level3 138 | MaxSpeed 139 | true 140 | true 141 | true 142 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 143 | true 144 | pch.h 145 | 146 | 147 | Console 148 | true 149 | true 150 | true 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | Create 160 | Create 161 | Create 162 | Create 163 | 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /CppWithNuGetPackageReference/CppWithNuGetPackageReference.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | 23 | 24 | Source Files 25 | 26 | 27 | Source Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /CppWithNuGetPackageReference/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: source file corresponding to pre-compiled header; necessary for compilation to succeed 2 | 3 | #include "pch.h" 4 | 5 | // In general, ignore this file, but keep it around if you are using pre-compiled headers. 6 | -------------------------------------------------------------------------------- /CppWithNuGetPackageReference/pch.h: -------------------------------------------------------------------------------- 1 | // Tips for Getting Started: 2 | // 1. Use the Solution Explorer window to add/manage files 3 | // 2. Use the Team Explorer window to connect to source control 4 | // 3. Use the Output window to see build output and other messages 5 | // 4. Use the Error List window to view errors 6 | // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project 7 | // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file 8 | 9 | #ifndef PCH_H 10 | #define PCH_H 11 | 12 | // TODO: add headers that you want to pre-compile here 13 | 14 | #endif //PCH_H 15 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | all 8 | 9 | 10 | 11 | 12 | 13 | <_NuGetTargetFallbackMoniker>$(_NuGetTargetFallbackMoniker);native,Version=v0.0 14 | 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jeroen Janssen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CppWithNuGetPackageReference 2 | Example Cpp project that uses NuGet PackageReference (instead of packages.config) 3 | 4 | ## Why PackageReference instead of packages.config? 5 | 6 | VisualStudio (for C++ vcxproj) only supports packages.config by default. 7 | However MSBuild NuGet integration is done in a generic way, it is just that the VS NuGet integration only supports packages.config. 8 | 9 | More information on the benefits of using PackageReferences can be found at the Official Microsoft NuGet documentation: 10 | [Benefits of using PackageReference](https://docs.microsoft.com/en-us/nuget/reference/migrate-packages-config-to-package-reference#benefits-of-using-packagereference). 11 | 12 | The [Microsoft.Build.CentralPackageVersions](https://github.com/Microsoft/MSBuildSdks/tree/master/src/CentralPackageVersions) 13 | MSBuild project SDK allows project tree owners to manage their NuGet package versions in one place. 14 | Stock NuGet requires that each project contain a version. You can also use MSBuild properties to manage versions. 15 | 16 | ## How 17 | Example using https://github.com/AArnott/Nerdbank.GitVersioning dependency purely during development. 18 | 19 | ### Directory.Build.props 20 | We store MSBuild settings in the solution root folder file `Directory.Build.props` since this is an offical (and very clean) way to 21 | [customize your build](https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2017#directorybuildprops-and-directorybuildtargets). 22 | 23 | ### Add NuGet PackageReference 24 | 25 | ``` 26 | 27 | 28 | all 29 | 30 | 31 | ``` 32 | 33 | ### Run MSBuild Restore 34 | `msbuild /t:restore CppWithNuGetPackageReference.sln` 35 | 36 | ### Add _NuGetTargetFallbackMoniker 37 | It seems adding a PackageReference is not enough. 38 | Because during the build we get an error `Your project does not reference ".NETFramework,Version=v4.0" framework.` 39 | 40 | From normal (packages.config) based NuGet package installation, we determine that NuGet is `targeting 'native,Version=v0.0'`. 41 | 42 | And by looking at `C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(186,5)` 43 | we can understand how a possible solution might look: 44 | 45 | ``` 46 | ... 47 | 57 | ... 58 | ``` 59 | 60 | It seems there is a `$(_NuGetTargetFallbackMoniker)` that is passed as additional option to the `TargetMonikers` parameter. 61 | Although there is no official documentation on this, it looks promising since it is seems to be used as a possible workaround for 'UAP' projects. 62 | 63 | That means we can use the same mechanism to target 'native,Version=v0.0': 64 | ``` 65 | 66 | <_NuGetTargetFallbackMoniker>$(_NuGetTargetFallbackMoniker);native,Version=v0.0 67 | 68 | ``` 69 | 70 | 71 | ## Technical Details 72 | 73 | * VS UI "Restore NuGet Packages" does not restore based on PackageReference 74 | 75 | `All packages are already installed and there is nothing to restore.` 76 | 77 | However, `MSBuild /t:restore` on solution/project does actually restore: 78 | ``` 79 | D:\GitHub\CppWithNuGetPackageReference>msbuild /t:restore CppWithNuGetPackageReference.sln 80 | Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework 81 | Copyright (C) Microsoft Corporation. All rights reserved. 82 | 83 | Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch. 84 | Build started 26-1-2019 21:08:42. 85 | Project "D:\GitHub\CppWithNuGetPackageReference\CppWithNuGetPackageReference.sln" on node 1 (Restore target(s)). 86 | ValidateSolutionConfiguration: 87 | Building solution configuration "Debug|x64". 88 | Restore: 89 | Restoring packages for D:\GitHub\CppWithNuGetPackageReference\CppWithNuGetPackageReference\CppWithNuGetPackageReference.vcxproj... 90 | Committing restore... 91 | Generating MSBuild file D:\GitHub\CppWithNuGetPackageReference\CppWithNuGetPackageReference\obj\CppWithNuGetPackageReference.vcxproj.nuget.g.props. 92 | Generating MSBuild file D:\GitHub\CppWithNuGetPackageReference\CppWithNuGetPackageReference\obj\CppWithNuGetPackageReference.vcxproj.nuget.g.targets. 93 | Writing lock file to disk. Path: D:\GitHub\CppWithNuGetPackageReference\CppWithNuGetPackageReference\obj\project.assets.json 94 | Restore completed in 390,42 ms for D:\GitHub\CppWithNuGetPackageReference\CppWithNuGetPackageReference\CppWithNuGetPackageReference.vcxproj. 95 | 96 | NuGet Config files used: 97 | C:\Users\japj\AppData\Roaming\NuGet\NuGet.Config 98 | C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config 99 | 100 | Feeds used: 101 | https://api.nuget.org/v3/index.json 102 | C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\ 103 | Done Building Project "D:\GitHub\CppWithNuGetPackageReference\CppWithNuGetPackageReference.sln" (Restore target(s)). 104 | 105 | 106 | Build succeeded. 107 | 0 Warning(s) 108 | 0 Error(s) 109 | 110 | Time Elapsed 00:00:01.13 111 | ``` 112 | 113 | 114 | 115 | * VS Build with PackageReference restored package fails with `Your project does not reference ".NETFramework,Version=v4.0" framework.` 116 | 117 | ``` 118 | 1>------ Rebuild All started: Project: CppWithNuGetPackageReference, Configuration: Debug x64 ------ 119 | 1>Build started 26-1-2019 21:10:19. 120 | 1>Target GetBuildVersion: 121 | 1> Building version 0.0.2.18725 from commit 25492f4145c10ea960ec419ae9243811f20a148e 122 | 1>Target GenerateNativeVersionInfo: 123 | 1> Copying file from "x64\Debug\\CppWithNuGetPackageReference.Version.rc.new" to "x64\Debug\\CppWithNuGetPackageReference.Version.rc". 124 | 1>Target PrepareForBuild: 125 | 1> Creating directory "D:\GitHub\CppWithNuGetPackageReference\x64\Debug\". 126 | 1> Creating directory "x64\Debug\CppWithN.F88D9F1D.tlog\". 127 | 1>Target ResolveNuGetPackageAssets: 128 | 1> C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(186,5): error : Your project does not reference ".NETFramework,Version=v4.0" framework. Add a reference to ".NETFramework,Version=v4.0" in the "TargetFrameworks" property of your project file and then re-run NuGet restore. 129 | 1>Done building target "ResolveNuGetPackageAssets" in project "CppWithNuGetPackageReference.vcxproj" -- FAILED. 130 | 1> 131 | 1>Done building project "CppWithNuGetPackageReference.vcxproj" -- FAILED. 132 | 1> 133 | 1>Build FAILED. 134 | 1> 135 | 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(186,5): error : Your project does not reference ".NETFramework,Version=v4.0" framework. Add a reference to ".NETFramework,Version=v4.0" in the "TargetFrameworks" property of your project file and then re-run NuGet restore. 136 | 1> 0 Warning(s) 137 | 1> 1 Error(s) 138 | 1> 139 | 1>Time Elapsed 00:00:00.26 140 | ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== 141 | ``` 142 | 143 | * Installing a NuGet package through the normal UI (with packages.config) results in: 144 | ``` 145 | Attempting to gather dependency information for package 'Nerdbank.GitVersioning.2.3.38' with respect to project 'ConsoleApplication1', targeting 'native,Version=v0.0' 146 | Gathering dependency information took 82,39 ms 147 | Attempting to resolve dependencies for package 'Nerdbank.GitVersioning.2.3.38' with DependencyBehavior 'Lowest' 148 | Resolving dependency information took 0 ms 149 | Resolving actions to install package 'Nerdbank.GitVersioning.2.3.38' 150 | Resolved actions to install package 'Nerdbank.GitVersioning.2.3.38' 151 | Retrieving package 'Nerdbank.GitVersioning 2.3.38' from 'nuget.org'. 152 | Adding package 'Nerdbank.GitVersioning.2.3.38' to folder 'D:\Temp\ConsoleApplication1\packages' 153 | Added package 'Nerdbank.GitVersioning.2.3.38' to folder 'D:\Temp\ConsoleApplication1\packages' 154 | Added package 'Nerdbank.GitVersioning.2.3.38' to 'packages.config' 155 | Executing script file 'D:\Temp\ConsoleApplication1\packages\Nerdbank.GitVersioning.2.3.38\tools\Install.ps1'... 156 | Could not find an AssemblyInfo.cs file at 'D:\Temp\ConsoleApplication1\ConsoleApplication1\Properties\AssemblyInfo.cs'. Skipping version.json generation. 157 | Successfully installed 'Nerdbank.GitVersioning 2.3.38' to ConsoleApplication1 158 | Executing nuget actions took 2,83 sec 159 | Time Elapsed: 00:00:03.1618944 160 | ========== Finished ========== 161 | ``` 162 | 163 | * Building end result: Success, MSBuild targets `GetBuildVersion` and `GenerateNativeVersionInfo` from `Nerdbank.GitVersioning` are called during build 164 | and the executable is correctly stamped with version information. 165 | ``` 166 | 1>------ Rebuild All started: Project: CppWithNuGetPackageReference, Configuration: Debug x64 ------ 167 | 1>Build started 26-1-2019 21:46:43. 168 | 1>Target GetBuildVersion: 169 | 1> Building version 0.0.5.61746 from commit 32f18dae142924cf3d180b5a5cca001cda3a9a67 170 | 1>Target GenerateNativeVersionInfo: 171 | 1> Copying file from "x64\Debug\\CppWithNuGetPackageReference.Version.rc.new" to "x64\Debug\\CppWithNuGetPackageReference.Version.rc". 172 | 1>Target PrepareForBuild: 173 | 1> Creating directory "D:\GitHub\CppWithNuGetPackageReference\x64\Debug\". 174 | 1> Creating directory "x64\Debug\CppWithN.F88D9F1D.tlog\". 175 | 1>Target InitializeBuildStatus: 176 | 1> Creating "x64\Debug\CppWithN.F88D9F1D.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified. 177 | 1>Target ClCompile: 178 | 1> pch.cpp 179 | 1> CppWithNuGetPackageReference.cpp 180 | 1>Target Link: 181 | 1> CppWithNuGetPackageReference.vcxproj -> D:\GitHub\CppWithNuGetPackageReference\x64\Debug\CppWithNuGetPackageReference.exe 182 | 1>Target FinalizeBuildStatus: 183 | 1> Deleting file "x64\Debug\CppWithN.F88D9F1D.tlog\unsuccessfulbuild". 184 | 1> Touching "x64\Debug\CppWithN.F88D9F1D.tlog\CppWithNuGetPackageReference.lastbuildstate". 185 | 1> 186 | 1>Build succeeded. 187 | 1> 0 Warning(s) 188 | 1> 0 Error(s) 189 | 1> 190 | 1>Time Elapsed 00:00:02.56 191 | ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========== 192 | ``` --------------------------------------------------------------------------------