Skip to content

Building a Sybase-NuGet-package with NuGet Package Explorer

September 25, 2017

This package will handle the unmanaged Sybase-assemblies that can not be referenced in your project but have to reside in the “bin”-folder. I will call the package Company.Sybase.1.0.0.nupkg.

Package structure

  • build
    • net
      • Company.Sybase.targets
  • lib
    • net20
      • Sybase.AdoNet2.AseClient.dll
      • Sybase.Data.AseClient.dll
    • net40
      • Sybase.AdoNet4.AseClient.dll
      • Sybase.Data.AseClient.dll
    • Unmanaged
      • sybdrvado115a.dll

Company.Sybase.nuspec

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
	<metadata>
		<authors>Company</authors>
		<description>Sybase assemblies.</description>
		<id>Company.Sybase</id>
		<owners>Company</owners>
		<references>
			<reference file="Sybase.AdoNet2.AseClient.dll" />
			<reference file="Sybase.AdoNet4.AseClient.dll" />
			<reference file="Sybase.Data.AseClient.dll" />
		</references>
		<requireLicenseAcceptance>false</requireLicenseAcceptance>
		<title>Company.Sybase</title>
		<version>1.0.0</version>
	</metadata>
</package>

Company.Sybase.targets

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<PropertyGroup>
		<BuildDependsOn>
			ResolveSybaseReferenceDependencies;
			ResolveSybaseDependenciesOnBuild;
			$(BuildDependsOn);
		</BuildDependsOn>
		<CleanDependsOn>
			ResolveOutputPath;
			ResolveSybaseReferenceDependencies;
			ResolveSybaseDependenciesOnClean;
			$(CleanDependsOn);
		</CleanDependsOn>
		<CopyAllFilesToSingleFolderForPackageDependsOn>
			ResolveOutputPath;
			ResolveSybaseReferenceDependencies;
			ResolveSybaseDependenciesOnPublish;
			$(CopyAllFilesToSingleFolderForPackageDependsOn);
		</CopyAllFilesToSingleFolderForPackageDependsOn>
	</PropertyGroup>
	<Target Name="ResolveOutputPath">
		<PropertyGroup>
			<_ResolvedOutputPath>$(OutputPath)</_ResolvedOutputPath>
			<_ResolvedOutputPath Condition="!$(_ResolvedOutputPath.EndsWith('\'))">$(_ResolvedOutputPath)\</_ResolvedOutputPath>
		</PropertyGroup>
	</Target>
	<Target Name="ResolveSybaseDependenciesOnBuild">
		<Copy
			DestinationFolder="$(OutputPath)"
			SourceFiles="@(_SybaseReferenceDependency)"
		/>
	</Target>
	<Target Name="ResolveSybaseDependenciesOnClean">
		<Delete
			Files="$(_ResolvedOutputPath)%(_SybaseReference.Filename)%(_SybaseReference.Extension)"
		/>
		<Delete
			Files="$(_ResolvedOutputPath)%(_SybaseReferenceDependency.Filename)%(_SybaseReferenceDependency.Extension)"
		/>
	</Target>
	<Target Name="ResolveSybaseDependenciesOnPublish">
		<ItemGroup>
			<FilesForPackagingFromProject Include="@(_SybaseReferenceDependency)">
				<DestinationRelativePath>$(_ResolvedOutputPath)%(Filename)%(Extension)</DestinationRelativePath>
			</FilesForPackagingFromProject>
		</ItemGroup>
	</Target>
	<Target Name="ResolveSybaseReferenceDependencies">
		<ItemGroup>
			<_SybaseDataAseClientReferenceInternal Include="@(Reference)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('Sybase.Data.AseClient'))" />
		</ItemGroup>
		<PropertyGroup>
			<_SybaseDataAseClientReferenceInternalHintPath>%(_SybaseDataAseClientReferenceInternal.HintPath)</_SybaseDataAseClientReferenceInternalHintPath>
		</PropertyGroup>
		<PropertyGroup>
			<_SybasePackageLibraryPath>$(_SybaseDataAseClientReferenceInternalHintPath.Substring(0, $([MSBuild]::Add($(_SybaseDataAseClientReferenceInternalHintPath.IndexOf('\lib\')), 5))))</_SybasePackageLibraryPath>
		</PropertyGroup>
		<ItemGroup>
			<_SybaseReference Include="%(Reference.HintPath)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('Sybase.'))" />
		</ItemGroup>
		<ItemGroup>
			<_SybaseReferenceDependency Include="$(_SybasePackageLibraryPath)Unmanaged\*.dll" />
		</ItemGroup>
	</Target>
</Project>
Advertisements

From → NuGet, Sybase

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: