NuGet.Config file Transforms? - tfs

Is there a way to transform a Nuget.Config file in a solution based on the solution configuration? I have one packageSource that I only use for resolving dependencies on my local machine. I don't want this packageSource to be used at all when I build the solution on the build server.
<?xml version="1.0" encoding="utf-8"?>
<packageSources>
<clear />
<add key="MyLocalFeed" value="\\MyNetworkShare" />
<add key="CompanyFeed" value="http://companynugetserver/" />
</packageSources>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
In the above sample Nuget.Config, I only want to use "MyLocalFeed" on my local development server ("Debug" configuration in the solution). Once all changes are checked-in and built on the build server, the "MyLocalFeed" packageSource should no longer appear/be ignored. I have to keep the <clear /> statement in the config, per company requirements.

No, we cannot transform a Nuget.Config file in a solution based on the solution configuration.
Based on your description you can use the "MyLocalFeed" for local development, and remove "MyLocalFeed" in the Nuget.Config file and use that file in TFS build to restore the packages from CompanyFeed.
But please note that the local packages may have other dependencies which are not included in CompanyFeed...
So we recommend using the same NuGet feed for development and CI, or you push all the related packages into theCompanyFeed.

Related

Automapper Failing when take latest from TFS

My team mate installed AutoMapper latest version in his workstation using
nuget in all the projects whereever referenced in the solution. In
package.config we can see the automapper latest version. It was building
properly in her machine. But when I take latest and run the project in my
machine, the Automapper failed but I can see in packages.config the new
version. But in reference the Automapper is showing not found with an yellow
icon.
It seems that the NuGet Package didn't restored Automapper successfully.
Possible duplicate with this question:TFS Can't Restore NuGet Package
Try to make sure both package sources are added to your NuGet.config file. Also ensure both sources are 'active'.
<configuration>
<packageSources>
<add key="nuget.org"
value="https://www.nuget.org/api/v2/" />
<add key="example.com"
value="http://example.com/feed/nuget/" />
</packageSources>
<activePackageSource>
<add key="All"
value="(Aggregate source)" />
</activePackageSource>
</configuration>

How can I prevent repositories.config from being automatically added to TFS?

I am using NuGet v2.8.60610.756. Every time I build a solution in VS2013, packages/repositories.config is automatically added to source control (TFVC) as a pending change. How can I prevent this?
I have added a .tfignore file at the solution root with the following entries, but it does not make a difference.
## Ignore the NuGet packages folder in the root of the repository
packages
packages/*
I have also set disableSourceControlIntegration to true in .nuget/NuGet.config
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>

Deploying Bitbucket to Azure Web Site: add private nuget package server

I have set up a website on Azure to deploy through a Bitbucket repository. The process fails when it tries to install nuget packages which are stored on a private nuget server, not nuget.org. Is there a way to specify where to restore the nuget packages from so that Azure can restore these packages?
You can add a custom NuGet.config file at the same level as your .SLN file.
You can then make the following modifications (assuming that your private feed requires authentication, create a set of credentials which only are used for this site):
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="custom_package_source" value="https://custom_package_source/nuget/v1/FeedService.svc/" />
</packageSources>
<disabledPackageSources />
<packageSourceCredentials>
<custom_package_source>
<add key="Username" value="CustomUsername" />
<add key="ClearTextPassword" value="CustomPassword" />
</custom_package_source>
</packageSourceCredentials>
When you deploy via Kudu, this should allow the build process to discover your private feed, authenticate & restore your packages.
If you do not require authentication against your private feed, remove the <packageSourceCredentials> element.

SQLite.Interop.dll not getting picked up by OctoPack

I've got a relatively new MVC5 project being built with TeamCity and deployed by Octopus Deploy. Everything was great until I added SQLite through NuGet. When the project gets built, I get an x86\SQLite.Interop.dll and an x64\SQLite.Interop.dll under my bin directory and it runs fine.
The problem is that OctoPack doesn't pick up either file; so, my NuGet package that I deploy to my server doesn't have it. How does one fix this?
The fine folks at Octopus Deploy pointed me to this help page that got me most of the way there.
For anyone else who runs into this particular problem, I originally added this to my .nuspec file:
<files>
<file src="bin\x86\*.*" target="bin\x86" />
<file src="bin\x64\*.*" target="bin\x64" />
</files>
but nothing got copied; so, I changed it to this:
<files>
<file src="bin\x86\SQLite.interop.dll" target="bin\x86" />
<file src="bin\x64\SQLite.interop.dll" target="bin\x64" />
</files>
Then TeamCity had a build error because x86 and x64 were empty. It looks like OctoPack somehow runs before those files get copied. It's a hack that I hope to remove at some point, but I got things working by adding those two files to my project, and changing my nuspec file to this:
<files>
<file src="SQLiteFiles\x86\SQLite.interop.dll" target="bin\x86" />
<file src="SQLiteFiles\x64\SQLite.interop.dll" target="bin\x64" />
</files>
Also, don't forget to add OctoPackEnforceAddingFiles=true in TeamCity.
I did something similar, but I HATE checking in binaries to source control, so I added this to my nuspec file:
<files>
<file src="..\..\packages\System.Data.SQLite.Core.1.0.98.1\build\net45\x86\SQLite.interop.dll" target="x86" />
<file src="..\..\packages\System.Data.SQLite.Core.1.0.98.1\build\net45\x64\SQLite.interop.dll" target="x64" />
</files>
Just go yank them out of the packages dir, I guess you could do something like this:
<files>
<file src="..\..\packages\System.Data.SQLite.Core.*\build\net45\x86\SQLite.interop.dll" target="x86" />
<file src="..\..\packages\System.Data.SQLite.Core.*\build\net45\x64\SQLite.interop.dll" target="x64" />
</files>
And I think it'll work regardless of version
You need to add a nuspec file with a files element to tell octopack that it should include the SQLite.interop.dll binaries.
<files>
<file src="bin\x86\SQLite.interop.dll" target="x86" />
<file src="bin\x64\SQLite.interop.dll" target="x64" />
</files>
Then, you need to reorder the imports in your project file so that SQLite comes before Octopack, this will ensure that SQLite.interop.dll is copied before Octopack runs.
<Import Project="..\packages\System.Data.SQLite.Core.1.0.105.2\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.105.2\build\net451\System.Data.SQLite.Core.targets')" />
<Import Project="..\packages\OctoPack.3.0.42\tools\OctoPack.targets" Condition="Exists('..\packages\OctoPack.3.0.42\tools\OctoPack.targets')" />
Finally, make sure to add the parameter OctoPackEnforceAddingFiles=true, this tells octopack to include the files targeted by the Files element in the nuspec file.

NuGet web.config.transform issue

I'm creating a custom package that needs to modify the web.config file of the destination application, but my config changes never appear in the destination app after installation.
Here's my web.config.transform file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="AppInstalled" value="false"/>
</appSettings>
</configuration>
This key in the appSettings section is never applied.
Here's my nuspec file:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>http://mvcapp.codeplex.com/license</licenseUrl>
<projectUrl>http://mvcapp.codeplex.com/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<tags>mvc app</tags>
</metadata>
<files>
<file src="\bin\Release\MvcApp.MVC3.dll" target="lib" />
<file src="NuGet\Content\ajax-loader.gif" target="Content" />
<file src="NuGet\Content\web.config.transform" target="web.config" />
<file src="NuGet\Views\Install\Index.aspx" target="Views\Install\Index.aspx" />
</files>
</package>
Here's the command I run to package the project from the VS 2010 command prompt:
nuget pack mvcapp.csproj
Any Ideas?
Thanks.
The web.config.transform file needs to go into the content folder:
<file src="NuGet\Content\web.config.transform" target="content" />
I know this is an old question, but it's one of the top google results when searching for why a web.config.transform won't apply, so I hope I'm not out of place applying this here.
TLDR; - clear your nuget files from the target project's packages directory (or I assume up the version number) between iterations of testing.
Full Version;
I had this problem as well. I could see using NuGet Package explorer that my project was packaged appropriately. I had my web.config.transform under "content", and my libs under their respective lib folders. The dll's were getting deployed, the web.config.transform wasn't getting applied.
The destination project I was testing with was under source control, so I'd add the nuget package, see what happened, then rollback the whole directory. However I didn't notice that the packages folder wasn't under source control, so the folders from my initial package install were in there. I wasn't upping the version number in the package nuspec, either, because I didn't think I had to.
Ultimately I ended up having to clear my nuget package's directory from the project's packages directory, forcing the next nuget install attempt to recreate them.

Resources