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.
Related
Visual Studio 2019, .Net Standard 2.0
How do I include a custom msbuild targets file for the consuming project?
What is the official supported way of doing this?
I've already tried:
modifying the csproj file as per (Setting Nuget package target path for item in MSBuild project)
trying to specify a nuspec file as per (https://natemcmaster.com/blog/2017/11/11/build-tools-in-nuget/)
Nuspec:
<?xml version="1.0"?>
<package >
<metadata>
<id>TestingNugetContent</id>
<version>1.0.10</version>
<title>Blah</title>
<authors>Me</authors>
<owners>Me</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Blah</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2019</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="Immutable\*.*" target="content/Immutable/" />
<file src="Build\*.*" target="build/netstandard2.0/" />
</files>
</package>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<NoPackageAnalysis>true</NoPackageAnalysis>
<NuspecFile>TestingNugetContent.nuspec</NuspecFile>
<IntermediatePackDir>$(MSBuildProjectDirectory)/bin/$(Configuration)/publish/</IntermediatePackDir>
<PublishDir>$(IntermediatePackDir)$(TargetFramework)/</PublishDir>
<NuspecProperties>publishDir=$([MSBuild]::NormalizeDirectory($(IntermediatePackDir)))</NuspecProperties>
<Version>1.0.10</Version>
</PropertyGroup>
<ItemGroup>
<Compile Remove="build\**" />
<EmbeddedResource Remove="build\**" />
<None Remove="build\**" />
</ItemGroup>
<ItemGroup>
<None Include="build\netstandard2.0\TestingNugetContent.targets" />
</ItemGroup>
<Target Name="PublishAll" BeforeTargets="GenerateNuspec">
<ItemGroup>
<_TargetFramework Include="$(TargetFrameworks)" />
</ItemGroup>
<MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Publish" Properties="TargetFramework=%(_TargetFramework.Identity)" />
</Target>
</Project>
Checking the consumer's <***>.csproj.nuget.g.targets file the import project tag for this custom target is missing after installing the Nuget package
As per the docs, the props and targets file names must match the package id exactly. Your nuspec lists the <id> as TestingNugetContent, so the files must be TestingNugetContent.props and TestingNugetContent.targets. They should be either directly in the build/ folder in the package, or the build/<tfm>/ folder (I prefer to be more explicit, so I appriciate you used the netstandard2.0 TFM). Now, your csproj appears to specify a build\netstandard2.0\TestingNugetContent.targets, which looks correct, so I can only guess that it wasn't packed into the correct location somehow.
I don't currently have time to show an example on how to pack it, but you can inspect the contents of your nupkg using NuGet package explorer, or just opening it up as a zip file, see what's "wrong", then adjust your project and try again.
FYI, you shouldn't need to use a nuspec at all, you can use the MSBuild PackagePath metadata on items to specify where MSBuild items are packed. It's unclear to me what the purpose of your PublishAll target is supposed to be. If you added it as part of trying to get your targets file included, you can remove it.
I have a windows service that I need to pack into a nuget package with OctoPack, but I have to exclude a directory called "Config" and a few other config files (these are instance specific and this will be deployed to multiple instances.) However the files are always included no matter what I put in the nuspec file.
Project directory:
Config <dir>
Code <dir>
app.config
settings.config
service.csproj
service.nuspec
Nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<!-- Required elements-->
<id>service</id>
<version>0.0.0</version>
<description>service for app</description>
<authors>our team</authors>
</metadata>
<!-- Optional 'files' node -->
<files>
<file src="**" exclude="Config\" />
<file src="**" exclude="**\app.config" />
<file src="**" exclude="**\settings.config" />
</files>
</package>
Jenkins file:
bat "dotnet-octo pack --id=service --format=NuPkg --basePath=bin\\x64\\BuildServer --version=0.0.0.${env.BUILD_ID} --overwrite"
I'm sure there is an error in my nuspec file or something but I can't find any documentation for my specific case. Thanks.
Turns out I was way overthinking this. I just edited the Jenkins file to delete them before packing. Completely forgot that bat was an option.
bat "del bin\\x64\\BuildServer\\app.config"
bat "del bin\\x64\\BuildServer\\settings.config"
bat "rmdir /s /q bin\\x64\\BuildServer\\Config"
bat "dotnet-octo pack --id=service --format=NuPkg --basePath=bin\\x64\\BuildServer --version=0.0.0.${env.BUILD_ID} --overwrite"
However, the correct way to do it via nuspec would have been
<files>
<file src="bin\x64\BuildServer\**\*.*" exclude="bin\x64\BuildServer\app.config;bin\x64\BuildServer\settings.config;bin\x64\BuildServer\Config\*.xml" />
</files>
src means "include all directories and files in bin\x64\BuildServer, where all the dlls and such are after building. And exclude means except these files. Note all paths are relative to where your nuspec file is (this is important!!!).
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.
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>
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.