dotnet build ZIP package - remove lengthy folder structure - .net-core

I'm trying to create a ZIP package of my Azure Function so I can upload each build to a storage account and reference them directly via an app setting instead of performing actual deployments.
In Azure DevOps pipelines, I'm using dotnet build (and tried locally as well) with the following args:
dotnet build Solution.sln /nologo /p:PublishProfile=Release /p:configuration="Release" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)" /p:SkipInvalidConfigurations=true
It works pretty fine and creates ZIP packages of each project that I need to deploy. However, looking inside each ZIP file, it essentially has some parameter and info XML files and a long folder structure where the actual function resides:
FunctionName.zip\Content\C_C\Projects\ProjectName\Main\FunctionName\obj\Release\netcoreapp3.1\PubTmp\Out
I understand that the command is creating a deployment package, hence a bunch of XML files which could be useful for parameter substitutions or transformations.
But I just actually want a ZIP file of everything that resides within that Out folder. Is there any parameter I am missing?
I've checked dotnet publish and haven't been able to create a proper ZIP package on it, seems like you need to zip it up manually.

Related

Swift Package Plugin - Copy Build Artifact

Is it possible to create a build tool plugin that runs after the build and copies build artifacts to another location in the package directory?
For example, say I have an executable target named tool. Each time that I build tool, I'd like to copy the build artifact from .build/release/tool to ./tool so that it's available at the root of the package.
As far as I can tell, this can't be done. But I may be missing something.
(Crosspost: https://forums.swift.org/t/swift-package-plugin-copy-build-artifact/60765)

AssemblyInfo ingrored when building from GitLab-Runner

On a Windows machine there is a GitLab-Runner run from a domain user with admin rights. When I log as this user and call dotnet build -c release to build an ASP.NET Core app, the dll has all the information from the AssemblyInfo.cs file. When I do the same as part of a CI job, the produced dll is missing all this information (for example the version number).
The AssemblyInfo.cs file is not part of the repository, instead, it is produced by a prebuild event (using gitWCRev.exe tool). However after running some tests I can see that the AssemblyInfo.cs is actually generated when the job is run by the runner.
Any help as to why the file is ignored and how to overcome this issue would be appreciated.
At first I thought that this might be related to Pre-build task of Visual Studio project fails in GitLab Runner issue, but I don't get any build errors.
On the same machine, I build a .Net Framework app which has the same AssemblyInfo setup, but is compiled using msbuild /property:Configuration=Release by the runner and the produced dll file has all the expected information.
It turns out the problem was partially related to the AssemblyInfo.cs file not being part of the repository.
SDK-style csproj normally don't list the files in the project, but figure them out based on the folder contents. When dotnet build was run, AssemblyInfo.cs wasn't present in the project directory (GitLab-Runner usually clears out files not present in the repository before starting a job/pipeline), so build tools had no idea they needed to load it. It made no difference that the file was being created by the build tools.
The solution proved to be creating an empty AssemblyInfo.cs file before running dotnet build. This way build tools knew they needed to compile it. Actual compilation still happened after prebuild events, so all the needed information was there.
I created the empty AssemblyInfo.cs file using PowerShell:
New-Item -Path "Properties/AssemblyInfo.cs" -ItemType File
Also, checking the build logs helped me finally figure it out. To get the build logs I've called build tools like this:
dotnet build -c release /flp:v=diag
The .Net Framework app didn't have this problem because it wasn't an SDK-style project. All the files needed for compilation were listed in the project file and build tools knew to load them, even if they were created during the prebuild event.

How to exclude folders/projects from dotnet core publish task in Azure Build Pipeline (Classic version)?

I have an Azure DevOps GIT Repo with three different types of projects. Structure looks as follows;
Repository Structure
I have a Build Pipeline (Classic, not YAML) to build only the .Net Core Project as below.
Pipeline
The pipeline settings is pointed to consider only the NetCoreProject. The Restore, Build & Test tasks executes successfully. However, when it comes to the 'Publish' task the pipeline fails as it considers the entire repository (all projects) and not just NetCoreProject.
Actual cause of failure is in NetCPPProject folder there are some files without any extension (makefile, shortcut files, etc.) which the Publish task is not identifying and failing with below error.
##[error]Error: Failed find: ENOENT: no such file or directory, stat 'D:\a\1\s\NetCPPProject\inc'
Note: inc is a shortcut file (without any extension) and it is required to be present in the folder.
I tried following which did not work;
Added .artifactignore to ignore other folders but the .Net Core 'Publish' task seems not to consider that.
Tried specifying the arguments to Publish tasks to consider only the NetCoreProject .sln file and also .csproj file, but issue still occurs with same error message.
Reconfirmed the file exists in Build.SourceDirectory with a command line task.
Question is, how to make .Net Core 'Publish' task to exclude NetCPPProject and only consider NetCoreProject?
how to make .Net Core 'Publish' task to exclude NetCPPProject and only consider NetCoreProject?
To achieve this goal, you could try the following steps:
Step1: Disable Publish web projects option in Dotnet Publish task.
Step2: Set the target csproj file in Path to project field
For example:
Repo:
Result:

VSTS build ended with empty build artifacts

We are using VSTS build using ASP.Net template. We are passing MSBuild Arguments as below-
/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\"
We see no build error. From the log we observe a line -
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /LRM -p ..\LRM\ -u -f -d PrecompiledWeb\LRM\
where LRM is the .NET sln name which we are building. This sln contains multiple projects along with the LRM website.
At the end of the build pipeline we see no artifact generated. We see a warning at the "Publish Build Artifacts" saying -
2018-01-03T06:07:47.9208838Z ##[warning]Directory 'D:\VSTS Agents\DEV-QAS\A1\66\a' is empty. Nothing will be added to build artifact 'drop'.
Use below as msbuild arguments (/p:OutDir="$(build.stagingDirectory)" is the diffrence)
/p:TransformConfigFiles=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:OutDir="$(build.stagingDirectory)"
Use Publish task Path to publish as "$(build.stagingDirectory)\_PublishedWebsites" if you only want the website output. If all the files in staging directory required use "$(build.stagingDirectory)" as path to publish
I don't know the cause, but perhaps this alternative set of MSDeploy-targeted MSBuild parameters will prove to be a workaround.
/p:SkipInvalidConfigurations=true /p:DeployTarget=Package /p:PackageTempRootDir="$(Build.ArtifactStagingDirectory)"
It is the website, so you can’t publish it as the web application.
First, as ChamindaC said that you can specify OutDir argument, but it won’t generate the web deployment package, you can archive the folder to zip through Archive task. (Note: the value should be /p:OutDir="$(build.stagingDirectory)\\")
Secondly, it can generate the publishproj file once creating publish profile (right click website > Publish Web App). So you can specify that file in Visual Studio Build or MSBuild task with your MSBuild Arguments to publish website to web deployment package.
ASP.Net Web API MSBuild Arguments: /p:OutDir=$(Build.ArtifactStagingDirectory) /p:SkipInvalidConfigurations=true
Publish Build Artifacts :
Path to Publish: $(Build.ArtifactStagingDirectory)_PublishedWebsites
The above configuration is working for me, please check the image for details.

MSBUILD command to generate APPXUPLOAD file for cordova application from Visual Studio

Can you please guide me with the MSBUILD command line to build appxupload files for a cordova application built using Visual Studio 2015.
Am using the below command but its not generating the appxupload file.
msbuild windowsbuild.jsproj /t:Build /p:Configuration=Release;Platform="Windows-x64" /p:AppxPackageIsForStore=true /p:BuildAppxUploadPackageForUap=true /p:UapAppxPackageBuildMode=StoreUpload
Also in case , I give multiple platforms, like Platform =windows-x86|Windows-x64|Windows-ARM, it gives me an invalid platform name error.
NOTE: Am able to successfully generate the app package using Project - > Create App Package option . I need to automate this outside of visual studio hence exploring the command line option.
Thanks for your help.
RAMYA M
I got the MSBUILD command that worked and generated the AppPackage.,
In the below command , if we change the CordovaBundlePlatforms=x86 OR CordovaBundlePlatforms=x64 , we can get platform specific AppPackage.
I required a single appxupload file for x86,x64 and ARM architecture
The output consists of ps1 file (to install on desktop) , appxbundle and .cer files and also a .appxupload file and I confirm that all of them are working fine.
"C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe" C:\Project\MyCode\platforms\windows\CordovaApp.Windows10.jsproj /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo /p:Configuration=release /p:Platform=arm /p:CordovaBundlePlatforms="x86|x64|arm"
Thanks for your inputs, appreciate the same.
Regards
RAMYA M
Am able to successfully generate the app package using Project - > Create App Package option . I need to automate this outside of visual studio hence exploring the command line option.
To manually create appxupload file, you need to create .appx and .appxsym files first.
You can Create .appx file with MakeAppx.exe Tool.
.appxsym file is a compressed .pdb file.
Then you can create .appxupload file by following steps:
Place the .appx and the .appxsym in a folder
Zip the folder
Change the zipped folder extension name from .zip to .appxupload

Resources