Problems building web deploy package - c#

Using visual studio I was able to configure a profile to create a web deploy package zip. I named the profile "deploy". I want to be able to do this from CI. This is the command line I have so far. I've been throwing every combination of options I've seen in the dozen blog posts out there:
msbuild HelloBeanstalk4.csproj /p:DeployOnBuild=true /p:PublishProfile=deploy /p:Configuration=Release;Platform="Any CPU" /p:PackageLocation="D:\x.zip" /p:OutputPath="d:" /p:DeployTarget=deploy /tv:14.0
When I run this it just spits out the contents of the /bin as well as a _PublishedWebsites directory with the site files in it. It doesn't make a zip file. I am using VS2013 to build either a 4.0 or 4.5 site.
What am I doing wrong?

In Visual Studio what is the file path for the setting Publish | Connection | Package Location? Mine is set to obj\Release\Package\package.zip
When you Publish in Visual Studio does it create the zip file in that location?
When I run the command in the folder with the .csproj it builds the package zip in the location I specified in the profile:
msbuild /p:DeployOnBuild=true /p:PublishProfile=deploy
UPDATE:
Using VS 2013 Pro, below are the contents of my ./Properties/PublishProfiles/deploy.pubxml file:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>Package</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<DesktopBuildPackageLocation>obj\Release\Package\package.zip</DesktopBuildPackageLocation>
<PackageAsSingleFile>true</PackageAsSingleFile>
<DeployIisAppPath />
<PublishDatabaseSettings>
<Objects xmlns="">
...
</Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
<MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String" />
</ItemGroup>
</Project>
Compared to your pubxml file any notable differences?

Related

Producing Executable for a C# project in linux

I want to know how to produce a c# executable file on Linux as when I build all I get is a DLL file in the bin folder that I don't know how to execute.
Note: I'm using vscode as my code editor and Manjaro is my Linux distro.
Did you try command?
dotnet app_name.dll
I guess a Publish Profile is What You are looking for.
Add a file named MyPublishProfile.pubxml to your project with this content:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<DeleteExistingFiles>false</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net6.0\publish\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<ProjectGuid>c21872b8-42b3-418a-ab47-103a60e7cd6c</ProjectGuid>
<SelfContained>true</SelfContained>
</PropertyGroup>
</Project>
save it and edit it (follow the provided links). then you can run
dotnet publish -p:publishProfile=MyPublishProfile
then you should have your excecutable. maybe you have to chmode it. you can read more here

Nuget package.targets not able to find files in copy task

Background: I have a library that's meant to be used with a C# game engine. That game engine has an editor that picks up plugins via a Plugins/ directory of the project (is not included in the build output). In order to make life easy for users I want to package my library and the associated editor plugins packaged and deployed together in a single nuget file. This way users don't have to manually manage the versions of two different sets of files.
Problem:
Nuget no longer has the ability to copy content files over by default. Based on searching the only way to accomplish this is with tasks set up in an msbuild package.targets file. So I have the following in my csproj
<ItemGroup>
<Content Include="../Parme.Frb.Example/Plugins/**/*">
<Pack>true</Pack>
<PackagePath>content\Plugins</PackagePath>
</Content>
<Content Include="Parme.Frb.targets">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
</ItemGroup>
The Parme.Frb.Example/Plugins folder contains the plugin files I want to include in the nuget file. My Parme.Frb.targets msbuild file contains:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<GluePluginFiles>$(MSBuildThisFileDirectory)..\content\Plugins\**\*</GluePluginFiles>
</PropertyGroup>
<Target Name="CopyGluePlugin" BeforeTargets="PreBuildEvent">
<Copy SourceFiles="$(GluePluginFiles)"
DestinationFolder="$(ProjectDir)Plugins\%(GluePluginFiles.RecursiveDir)"
SkipUnchangedFiles="true" />
</Target>
</Project>
The intention is that it will copy all files from the <nuget-cache>/<package>/content/Plugins directory and recursively copy it tho the project's Plugins/ directory.
When I look at the built nuget file I see all the included content files
So I load this nuget file into a blank project and run a build, which produces the following errors:
Build started 4/12/2021 4:56:42 PM.
Logging verbosity is set to: Normal. 1>Project "C:\Users\me\RiderProjects\NugetTest\NugetTest\NugetTest.csproj" on node 1 (build target(s)).
1>C:\Users\me\.nuget\packages\parme.frb\0.8.3-test10\build\Parme.Frb.targets(7,9): error MSB3030: Could not copy the file "C:\Users\me\.nuget\packages\parme.frb\0.8.3-test10\build\..\content\Plugins\**\*" because it was not found.
1>Done Building Project "C:\Users\me\RiderProjects\NugetTest\NugetTest\NugetTest.csproj" (build target(s)) -- FAILED.
Build FAILED.
"C:\Users\me\RiderProjects\NugetTest\NugetTest\NugetTest.csproj" (build target) (1) ->
(CopyGluePlugin target) ->
C:\Users\me\.nuget\packages\parme.frb\0.8.3-test10\build\Parme.Frb.targets(7,9): error MSB3030: Could not copy the file "C:\Users\me\.nuget\packages\parme.frb\0.8.3-test10\build\..\content\Plugins\**\*" because it was not found.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.33
However, files most definitely do exist in this directory:
PS C:\Users\me> ls C:\Users\me\.nuget\packages\parme.frb\0.8.3-test10\build\..\content\Plugins
Directory: C:\Users\me\.nuget\packages\parme.frb\0.8.3-test10\content\Plugins
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 4/12/2021 4:56 PM Parme.Frb.GluePlugin
I've tried reorganizing the nuget package to remove the .., I've tried removing the GluePlugins. part of the RecursiveDir (which most tasks don't seem to have but that causes a different error`, etc.. I've tried a ton of stuff and can't get this to work.
Does anyone have any idea on how I can get this copying, without manually specifying each file?
I don't know specifically why this works, but after a lot of trial and error I got it working via:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<GluePluginFile Include="$(MSBuildThisFileDirectory)..\content\Plugins\**\*" />
</ItemGroup>
<Target Name="CopyGluePlugin" BeforeTargets="PreBuildEvent">
<Message Importance="normal" Text="Copying Glue plugin files" />
<Copy SourceFiles="#(GluePluginFile)"
DestinationFolder="$(ProjectDir)\Plugins\%(RecursiveDir)"
SkipUnchangedFiles="true" />
</Target>
</Project>

C# - Unable to change ApplicationVersion from MSBuild script

I'm a newbie trying to modify on publish the ApplicationVersion value by AssemblyVersion one on a MS Office AddIn.
Here is my csproj :
<Target Name="SetAssemblyVersionToPublish" AfterTargets="AfterCompile">
<ReadLinesFromFile File="Properties\AssemblyInfo.cs">
<Output TaskParameter="Lines" ItemName="AssemblyVersion" />
</ReadLinesFromFile>
<PropertyGroup>
<In>#(AssemblyVersion)</In>
<Pattern>\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+).(\d+)</Pattern>
<Out>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</Out>
<ApplicationVersion>$(Out.Remove(0, 28))</ApplicationVersion>
</PropertyGroup>
<Message Text="app Version : $(ApplicationVersion)" Importance="High" />
When I publish the app from Visual Studio 2015, logs show the good version :
app Version : 4.4.9.0
But in fact it is the ApplicationVersion defined in VS that is used :
<ApplicationVersion>1.0.0.0</ApplicationVersion>
I already tried :
reset all VS settings
disable any vs third party extensions
use safemode
if I publish a WPF app, it works well
Any one would know why I get this change ?
Update
After some test, I found that MSBUILD use a different target file for VSTO : MSBuild\Microsoft\VisualStudio\v14.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets.
It seems to use PublishVersion which is a copy of ApplicationVersion. I don't know why but if I set ApplicationVersion in my target, it does not update the PublishVersion... If I set the publishVersion, I get the good version in my bin folder, but publishing failed (don't copy to publish folder because it still want to get the folder with 1_0_0_0 in bin).
It may be a problem with a bad step which launch my target, but I don't figure when it must be done.
Any help ?
UPDATE 2
It seems to be a bug with VS2015 publishing tool. If I try with msbuild.exe command line, it works well:
On VS I get an error asking for the below folder :
Whereas with the following msbuild command, it works :
MSBuild xxx\ExcelAddIn1\ExcelAddIn1\ExcelAddIn1.csproj /t:clean;publish
Anyone know what can be done as a workaround ?
First of all, I have a question, when I use your code in a winform project and execute publish, I got an error like:
After I test, I found that
ApplicationVersion which you got is illegal three digits instead of four digits, so there is a problem with your method of obtaining AssemblyVersion.
In general, the publish version is under Project Properties(right-click on your project)-->Publish
You can note that it is four digits.
Which proves that you have miss a node on Pattern property.
Suggestion
You should use
<Pattern>\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+).(\d+)</Pattern>
The whole code are:
<Target Name="AfterCompile">
<ReadLinesFromFile File="Properties\AssemblyInfo.cs">
<Output TaskParameter="Lines" ItemName="AssemblyVersion" />
</ReadLinesFromFile>
<PropertyGroup>
<In>#(AssemblyVersion)</In>
<Pattern>\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+).(\d+)</Pattern>
<Out>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</Out>
<ApplicationVersion>$(Out.Remove(0, 28))</ApplicationVersion>
</PropertyGroup>
<Message Text="app Version : $(ApplicationVersion)" Importance="High" />
</Target>
It will reads the AssemblyVersion from the AssemblyInfo.cs file.
In my side, it is
Actually, your method already works and it overwrite the publish version for the app.
I think you have read the first part of the build output log like this:
It is only the default system initial value at the beginning of the build, and it is just displayed there. And then through your custom msbuild script actually has overwritten its value.
Before executing publish, you should delete the publish folder, bin and obj folder, then execute the publish, you can enter the folder to check:
Update 1
I think your csproj file has imported some targets or props file which has other targets overwrite the AfterCompile target. So your method failed.
That is, your method may be overwritten elsewhere.
So I think you should not use AfterCompile as the target name and should name it as another to distinguish between them.
Use this:
<Target Name="SetAssemblyVersionToPublish" AfterTargets="AfterCompile">
<ReadLinesFromFile File="Properties\AssemblyInfo.cs">
<Output TaskParameter="Lines" ItemName="AssemblyVersion" />
</ReadLinesFromFile>
<PropertyGroup>
<In>#(AssemblyVersion)</In>
<Pattern>\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+).(\d+)</Pattern>
<Out>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</Out>
<ApplicationVersion>$(Out.Remove(0, 28))</ApplicationVersion>
</PropertyGroup>
<Message Text="app Version : $(ApplicationVersion)" Importance="High" />
</Target>
Or, You can add a file called Directory.Build.targets file on your project folder
and then add my code on it:
<Project>
<Target Name="SetAssemblyVersionToPublish" AfterTargets="AfterCompile">
<ReadLinesFromFile File="Properties\AssemblyInfo.cs">
<Output TaskParameter="Lines" ItemName="AssemblyVersion" />
</ReadLinesFromFile>
<PropertyGroup>
<In>#(AssemblyVersion)</In>
<Pattern>\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+).(\d+)</Pattern>
<Out>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</Out>
<ApplicationVersion>$(Out.Remove(0, 28))</ApplicationVersion>
</PropertyGroup>
<Message Text="app Version : $(ApplicationVersion)" Importance="High" />
</Target>
</Project>
Then, delete bin, obj, publish folder and then republish again to check it.
If the issue still persists, you should try the following suggestions to troubleshoot the issue:
1) Try to reset vs settings by Tools-->Import and Export settings-->Reset all vs settings
2) disable any vs third party extensions under Tools-->Extensions and Updates -->Installed, after that, close VS ,restart your project.
3) you could try devenv /safemode on the Developer Command Prompt for VS2015 to start a pure, initial vs to test your solution.
===============================================
Update 2
The MS Office Excel AddIn project is quite different from the traditional projects. And it is impossible by using this way.
As a workaround, I think you should use msbuild script to publish the project.
1) create a file called PublishExcel.proj
2) add these content on that file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="SetAssemblyVersionToPublish">
<!--you must specify the full path of the AssemblyInfo.cs from your project -->
<ReadLinesFromFile File="C:\Users\xxx\Documents\Visual Studio 2015\Projects\ExcelAddIn1\ExcelAddIn1\Properties\AssemblyInfo.cs">
<Output TaskParameter="Lines" ItemName="AssemblyVersion" />
</ReadLinesFromFile>
<PropertyGroup>
<In>#(AssemblyVersion)</In>
<Pattern>\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+).(\d+)</Pattern>
<Out>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</Out>
<ApplicationVersion>$(Out.Remove(0, 28))</ApplicationVersion>
</PropertyGroup>
<Message Text="app Version : $(ApplicationVersion)" Importance="High" />
<MSBuild Projects="C:\Users\Administrator\Documents\Visual Studio 2015\Projects\ExcelAddIn1\ExcelAddIn1\ExcelAddIn1.csproj" Properties="ApplicationVersion=$(ApplicationVersion)" Targets="Publish">
</MSBuild>
</Target>
</Project>
3) then open Developer Command prompt for VS2015 and then type:
msbuild xxx\xxx\PublishExcel.proj -t:SetAssemblyVersionToPublish
And the publish folder will be under the bin\Debug or Release\app.publish folder.
This function will work for MS Office Excel AddIn project.

Nuget: Including an exe as a Run-time dependency

I have an .exe app that I need to distribute with my C# app when it builds. I am trying to use Nuget to package it so that it will be included in the build root directory when building but am having trouble getting the behaviour I want.
Here is what I've got in my .nuspec file:
<?xml version="1.0"?>
<package>
<metadata>
<id>my.id</id>
<version>1.0.0</version>
<authors>me</authors>
<owners>me</owners>
<licenseUrl>myurl</licenseUrl>
<projectUrl>myurl</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A copy of an .exe so we can easily distribute it
with our applications without needing to include it in our VCS repo</description>
<releaseNotes>Initial test version</releaseNotes>
<copyright>Copyright 2018</copyright>
<dependencies>
</dependencies>
<packageTypes>
</packageTypes>
<contentFiles>
<files include="any\any\myexe.exe" buildAction="None" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="content\myexe.exe" target="content" />
</files>
</package>
This puts the myexe.exe file to my VS project when I install the Nuget Package but it does not copy the file when I build. What I'd like is for the file to by installed with my other app files when building and to keep it out of my VS project.
I've been reading docs here but am not sure how to make the nuspec file.
More Details:
Nuget 4.5.1
Visual Studio 2015
Note: the <files> and <contentFiles> might seem to be duplicating functionality. I'd like to employ both as I understand this will future-proof it for VS2017
Nuget: Including an exe as a Run-time dependency
First, I know you want to use some technologies for the future, but we have to know that these future-oriented technologies often have certain constraints and conditions.
For example, <contentFiles> is used for NuGet 4.0+ with PackageReference, neither of them is supported by Visual Studio 2015. See Using the contentFiles element for content files for some details.
If you are interested in the <contentFiles>, you can read the blog NuGet is now fully integrated into MSBuild.
Go back to our question now, according to above info, we should not use <contentFiles> when we use Visual Studio 2015. To resole this issue, we need to add a .targets file in the nuget package when you build the project:
The content of .targets file:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(ProjectDir)myexe.exe">
<Link>myexe.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CustomToolNamespace></CustomToolNamespace>
</None>
</ItemGroup>
</Project>
The .nuspec file like following:
<files>
<file src="build\YouNuGetPackageName.targets" target="build\YouNuGetPackageName.targets" />
<file src="content\myexe.exe" target="content\myexe.exe" />
</files>
Note: The name of the .targets file should be same as your nuget package name.
With this way, when you build your project, MSBuild/VS would copy the file myexe.exe to the output folder.
Besides, if you want to copy the file myexe.exe to other destination, you can replace the content of .targets file with a copy task, like:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyMyexe" BeforeTargets="Build">
<Message Text="Copy CopyMyexe to the folder."></Message>
<Copy
SourceFiles="$(ProjectDir)myexe.exe"
DestinationFolder="xxx\xxx\xx\myexe.exe"
/>
</Target>
</Project>
See Creating native packages and similar issue for some helps.
Hope this helps.

How can I exclude the bin folder from Visual Studio publish?

I want to exclude the bin folder from being copied to the publish directory.
Using Visual Studio 2015, Asp.Net Web Application Project
Below is my .pubxml file. Notice that "bin" is listed inside the ExcludeFoldersFromDeployment element. All of the other folders listed there are excluded as expected, but this bin folder is still copied!
The bin directory is different I imagine as it is not part of the project, but part of the build output. My build output path is pointing to a different directory than my publish and working correctly. why is the bin still being copied to the publish output directory?? can it be excluded??
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ExcludeFilesFromDeployment>Web.config;Default.aspx;packages.config</ExcludeFilesFromDeployment>
<ExcludeFoldersFromDeployment>bin;js;TestingUtils;TestPages;UI</ExcludeFoldersFromDeployment>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\website</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
you can use the following tag in your xml publish profile:
<ExcludeFoldersFromDeployment>bin<
I just inserted <ExcludeFoldersFromDeployment>bin</ExcludeFoldersFromDeployment> in my publish profile and it didnt include bin folder

Categories