Provide credentials to MSBuild publish step that uses FileSystem deployment in TeamCity - visual-studio-2012

I work in a dev environment where the computers aren't part of a domain. I'm trying to set up TeamCity 8.05 on one of the computers to publish check-ins to a test server for our QA team. I've got it working the way I want when I deploy to local directories on the TeamCity server, but when I try to publish to the QA server I run in to permissions problem. I have a share on the QA server with a local user who I want to authenticate with when doing my publish. Is this possible with MSBuild?
Command line switches to my MSBuild runner in TeamCity look like this:
/p:PublishProfile=./Alpha.publish /p:DeployOnBuild=true
/p:Configuration=Alpha /p:VisualStudioVersion=11.0
/p:UserName=QAServer\BuildUser /p:Password=somepass
The Alpha.publish file looks like this:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Alpha</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>\\QAServer\Alpha</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<PrecompileBeforePublish>True</PrecompileBeforePublish>
<EnableUpdateable>True</EnableUpdateable>
<DebugSymbols>False</DebugSymbols>
<WDPMergeOption>DonotMerge</WDPMergeOption>
</PropertyGroup>
</Project>
I get an 'Access to the path \\QAServer\Alpha is denied' message when this step runs. I assume this is because the build agent runs as a system account which can't access the QAServer.
I'm trying to avoid the overhead of using Web Deploy, but it looks like that would work for me if this isn't possible.

From Sayed I. Hashimi ‏on twitter:
FileSystem relies on windows auth. Passing in password is ignored.
Your build user will need write access
That's what I thought. My solution is to publish to local staging directory first, then use the SMB Deployer from the TeamCity Deployer plugin to move the files across the network. The plugin allows you to specify credentials.

Related

GenerateEFSQLScripts fails when trying to publish to IIS using Web Deploy from TeamCity

Running into a total dead-end here.
I've created a Publish Profile for a .net6 application that we want to publish to IIS with Web Deploy. In the Entity Framework Migration section, the option to "Apply this migration on publish" is selected.
When manually clicking publish, everything works. However, we want to automate this in TeamCity using the .NET build runner. The publish step fails at:
Generating Entity Framework SQL Scripts...
Executing command: dotnet ef migrations script --no-build --idempotent --configuration Release --output "C:\TeamCity\buildAgent\work\cbf95cc2b4413601\MySolution.Api\obj\Release\net6.0\PubTmp\EFSQLScripts\MySolution.Data.MyContext.sql" --context MySolution.Data.MyContext
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(221,5): error : Entity Framework SQL Script generation failed
Internal error message details: BuildMessage1 0 Text DefaultMessage ERROR 400682522803500 tags:'tc:parseServiceMessagesInside'
Error message is logged
Build FAILED.
I cannot find any specific error messages anywhere in any log. Looking in the Microsoft.NET.Sdk.Publish.TransformFiles.targets file shows that it's failing on GenerateEFSQLScripts - an MSBuild command that executes dotnet ef under the covers.
I thought this might be a case of dotnet ef not being installed on the build agent. But when I manually run the command myself from C:\TeamCity\buildAgent\work\cbf95cc2b4413601\MySolution.Api, it succeeds, and the SQL scripts are successfully created.
I also thought it might just be a case of the command being run in the wrong directory (i.e. in the root MySolution folder rather than the MySolution.Api folder), but explicitly setting the working directly fails at the same point, with the same error.
Has anyone seen this before? Or could point me to where an actual error might be located?

Environment Variable replacement in Nuget.config

We have dotnet core application with Nuget.config file . As part of azure devops CI pipeline, we want to read and replace environment variables in Nuget.config file. Environment/Pipeline variables(USERNAME and PWD) are configured in "Build Docker Image" Task in CI pipeline. The azure devops CI build server runs on Ubuntu machine.
Environment variables in MAC/Linux should be replaced in following way as per this documentation.
The syntax "$USERNAME" in Nuget.config is not working here. When we replace static username and password, it works fine.
Nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="abcFeed" value="https://somedevops.com/xyz/packaging/someApps/nuget/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <abcFeed>
      <add key="Username" value="$USERNAME"/>
      <add key="ClearTextPassword" value="$PWD"/>
    </abcFeed>
  </packageSourceCredentials>
</configuration>
We have tried below syntax with following documentation, none of them are working: $USERNAME, $(USERNAME), %USERNAME%, $USERNAME$
https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#example-config-file
https://intercom.help/appcenter/en/articles/2216043-restore-private-azuredevops-package-management-feeds-using-pat.
Setting an environment variable in a NuGet.Config file
What is correct syntax or way of replacing environment variables in Nuget.config file with azure devops pipeline?
You could use a Replace Tokens task instead, and configure this to process your nuget.config file.
However, you may want to consider using a Nuget service connection as that will avoid having to save the Nuget credentials as pipeline variables and also make them more secure as they will be exposed in plain text when replaced in the config file.
For more information about using Service Connections in Azure DevOps, see the Microsoft documentation at: https://learn.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml#sep-nuget
I believe our nuget docs need correcting. Use the same characters for environment variable replacement, regardless of platform: %myPW%
I tested successfully with dotnet.exe 3.0.100 on Ubuntu 18.*
Please engage with me on the tracking issue I have assigned to me: https://github.com/NuGet/Home/issues/8662

Packaging SSIS (.ispac) into NuGet Feed (Azure Artifacts)

I have to connect Octopus-Deploy to an external feed located on a Azure Devops Artifact Feed. I've successfully connected to the feed, but seeing how I packaged my SSIS project (.ispac) and SSDB project (.dacpac) as .dacpac and .ispac, it won't find them as it expects them to be in .NuGet format.
I haven't been able to try much as I'm pretty stuck.
N/A
I'm constrained to put whatever type of package I make on this feed to connect to from Octopus and deploy from. I have to have either have all my packages be NuGet Packages or find and alternate way that Octopus Deploy can find my packages on the Azure External Feed w/out them being NuGet. I'm only deploying SSDT things: i.e. dacpac, ispac, sql-agents, sql scripts etc.
You can make a NuSpec file which contains the things you need to package into NuGet to use a NuGet external feed in Octopus with. In the case of SSIS, you will want to reference the .ispac file in your nuspec file like so:
{
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>SSIS.ODSToDW</id>
<version>2.0.0</version>
<authors>blah</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ODSToDW ispac</description>
</metadata>
<files>
<file src="bin/Development/ODS-To-DW.ispac" target="ODS-To-DW.ispac" />
</files>
</package>
}
You'll then do a "build" pipeline in DevOps which builds your solution. In the case of ispac you will need to use SSIS Build (you can get it from the market place).
Upon building the solution so that the latest .ispac is formed, you then use NuGet pack pointed to your .nuspec file like so:
{
- task: NuGetCommand#2
inputs:
command: 'pack'
packagesToPack: '**/*.nuspec'
configuration: 'Release'
versioningScheme: 'byPrereleaseNumber'
majorVersion: '1'
minorVersion: '0'
patchVersion: '2'
packTimezone: 'local'
}
Then you can do a "NuGet push" to your Artifact feed in azure. From which Octopus will be able to connect using "external NuGet feed" which will allow you to using "Deploy Package" from the Octopus Process options from which you can point to your specific artifact using it's name and a post-deployment powershell script will allow you to deploy to your sql server.

Publish .Net Core to IIS - Process cannot access file

I am deploying my ASP .Net Core 2.0 app to my remote server using FTP. Remote Server is using IIS 8. When I publish my app, I get the following error.
Unable to add 'Project.dll' to the Web site. The process cannot access the file because it is being used by another process (550).
I been able to bypass this by manually creating an app_offline.htm first on the publish directory, and then publishing my app via Visual Studio 2017.
I was wondering, is there an easier way of doing this? or is there an easy way I can script this, so that app_offline gets created automatically before publish? and then deleted after publish?
Anyone that's curious, I gave up depending on VS to publish my .NET Core project. I'm now using WinSCP and _PublishToWeb.bat script I created to accomplish the task.
I first created a file called _app.offline.htm on root directory my publish folder. Then when I need to publish, I run the script below.
This script does the following:
1. Builds the .NET Core project to a specific folder, let's call it "_dist" folder.
2. Connects to my ftp server/publish folder and renames "_app_offline.html" to "app_offline.html", so that the server goes offline.
3. Synchronizes _dist folder with publish folder.
4. When done, changes "app_offline.htm" to "_app_offline.html", so the website is restarted.
_PublishToWeb.bat
echo off
echo Publishing to ProjectName (Optional)
set ProjectRemoteFolder=RemoteFolderName
set ConnectionString=ftp://username:password#serverIp:serverPort
set WinSCP="path to WinSCP.com"
set ProjectDistPath="a folder where dotnet publish will build the project to"
set WebAppProject="path of the project. dotnet publish will run here"
rem Build project and put it in to distribution folder
cd %WebAppProject%
dotnet publish -c Release -o %ProjectDistPath%
rem Connect to FTP and synchronize folder
%WinSCP% /command "open %ConnectionString%/%ProjectRemoteFolder%/" "mv _app_offline.htm app_offline.htm" "synchronize remote %ProjectDistPath%" "mv app_offline.htm _app_offline.htm" "exit"
rem pause
I'm sure there are better solutions out there, but this has been working well for me so far.

All but first deployment of Orchard CMS to Azure Web Apps Fails

In Visual Studio Online I have a scripted build that builds Orchard 1.9.1 from source then, using the Azure Web App Deployment task, deploys the compiled Web Deploy Package to Azure.
The first deployment to a fresh Web App instance works great and the system functions as expected. However, any subsequent deployment to the same Web App fails with:
Unable to perform the operation ("Delete File") for the specified
directory ("HtmlAgilityPack.dll"). This can occur if the server
administrator has not authorized this operation for the user
credentials you are using. Learn more at:
http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER.
The file specified in the error can be different, but the deployment fails consistently. The link in the error isn't of much help as the implementation details covered (IIS, root folder etc) are abstracted away in an Azure Web App.
Where should I look to fix this permissioning issue?
I went with the default build template for Azure Website when creating the build, details of which are below for info:
Build Step:
MSBuild Arguments:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.stagingDirectory)"
Azure Web App Deployment step:
Pertinent information for the build log:
2015-09-28T05:36:22.7928424Z Package= C:\a\d8c9303e\staging\Orchard.Web.zip
2015-09-28T05:36:22.7938416Z Slot=
2015-09-28T05:36:22.7938416Z AdditionalArguments=
2015-09-28T05:36:22.8028415Z packageFile= Find-Files -SearchPattern C:\a\d8c9303e\staging\Orchard.Web.zip
2015-09-28T05:36:22.8198428Z packageFile= C:\a\d8c9303e\staging\Orchard.Web.zip
2015-09-28T05:36:22.8258420Z Get-AzureWebSite -Name **** -ErrorAction SilentlyContinue
2015-09-28T05:36:28.4361621Z Publish-AzureWebsiteProject -Name "****" -Package "C:\a\d8c9303e\staging\Orchard.Web.zip"
2015-09-28T05:36:33.8798112Z ##[error]Unable to perform the operation ("Delete File") for the specified directory ("HtmlAgilityPack.dll"). This can occur if the server administrator has not authorized this operation for the user credentials you are using.
2015-09-28T05:36:33.8818107Z ##[error] Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER.
Use the provided Orchard.proj msbuild script using the Precompiled target.

Resources