Windows azure project replace ServiceConfiguration.Cloud.cscfg - azure

I have two MVC projects. And I created two WindowsAzure project:WindowsAzure1-> which package MVC1 , and WindowsAzure2-> which package MVC2 project. After CheckIn on Local TFS 2012, I build my solution. MSBuild Arguments:
/t:Publish /p:PublishDir=c:\drops\app.publish\
After Build I see 3 file, instead 4.
1.WindowsAzure1.cspkg
2.WindowsAzure2.cspkg
3.ServiceConfiguration.Cloud.cscfg//It contain config WindowsAzure2.cspkg
I tried to rename ServiceConfiguration.Cloud.cscfg, but it doesn't rename.
So, I think the better place package on different folder. But problem that in the future MVC and Azure project will be unknown count. So I need automatically create folder contains name project. So how can it do?

Simple Way to create dynamic folders is through PowerShell Script.
Lets say you have folder structure of projects in following way -
Then you can following script to generate package folders -
# Solution directory, which contains all the projects
$path = "C:\Solution"
$folders = Get-ChildItem -Path $path
foreach ($folder in $folders)
{
if ($folder.Attributes -eq "Directory")
{
if($folder.Name -like "*.Cloud")
{
New-Item -Path "$($path)\$($folder.Name)package" -ItemType "Directory"
}
}
}
Output will be -
Then you can use CSPack utility and PowerShell combination to create package and save configuration file to the location of your interest.
http://www.intstrings.com/ramivemula/articles/jumpstart-30-create-azure-cloud-service-package-cspkg-of-visual-studio-2013-project-solution-using-powershell/

Related

Azure function app, Powershell 7.2 dll module install

I have this powershell script which works very well on my computer. I use the x64 and powershell 7.2.
The problem is when I publish the code to Azure, there is a module missing. The module is a .net System.Data.OleDb.
ERROR: Exception calling "Open" with "0" argument(s): "The 'MSOLAP' provider is not registered on the local machine."
I have tried to add the .dll file to Module folder, that i created but function app doesn't load it for some reason.
Structure of the function app
host.json
local.settings.json
powerbitablerefresh
run.ps1
function.json
Modules
Microsoft.AnalysisServices.AzureClient.dll
profile.ps1
requirements.psd1
inside requirements I have:
'Az.Keyvault' = '4.*'
'Az.Accounts' = '2.*'
'Az.AnalysisServices' = '1.*'
'SqlServer' = '21.1.18256'
My question is, how do I install .dll on a function app?
how do I install .dll on a function app?
You can install .dll files by following below workaround:
Firstly, Login to Azure
Then open your Function App
Then Click on Advanced tools , then click on Go
Then Click on Tools, Then click on Zip Push Depoly like below:
Then Click on your function app
Then click on bin folder and after it opens, drag your .dll file over there and then you can reference them in your function app:
The right answer is that add the .dll files to the C:\home\site\wwwroot\ and then in the powershell script run it like this
Add-Type -Path (Join-Path $PSScriptRoot "Microsoft.Identity.Client.dll")
Add-Type -Path (Join-Path $PSScriptRoot "Microsoft.AnalysisServices.AdomdClient.dll")
It will then create a connection

Blazor WebAssembly Application fails to load due to integrity errors

We have developed a Blazor WebAssembly Application that has already gone into productive usage for a certain group of customers.
The Application works well in all Browsers with Standard Security settings. However, this morning I got a call from one of the customers, where the Application did not load at all in their Chrome Browser.
I saw the following Errors in the console:
Unknown error occurred while trying to verify integrity.
Failed to load resource: the server responded with a status of 403 (forbidden)
Failed to find a valid digest in the 'integrity' attribute for ressource '<somepath.dll>' with SHA-256 integrity <sha56>. the resource has been blocked
Now my question is, what could cause this? Is this a Browser Security setting, or another security setting e.g on server, in code etc.? How can I fix this?
Here's a picture of the errors mentioned above
The most likely reason why this is happening, is that some Antiviruses block the execution of downloaded .dll files. That's why it is working in some networks, but doesn't in some others.
What you can do, and what is also suggested as a Workaround by microsoft, is to rename all .dll to .bin - and also change the config json. it worked in my case.
I use the following PowerShell function for that:
Function Hide-BlazorDLL {
Param(
[string]$Path = (Get-Location).Path
)
<#
According to the following Links:
https://github.com/dotnet/aspnetcore/issues/19552
https://github.com/dotnet/aspnetcore/issues/5477#issuecomment-599148931
https://github.com/dotnet/aspnetcore/issues/21489
https://gist.github.com/Swimburger/774ca2b63bad4a16eb2fa23b47297e71
#>
# Test if path is correct and accessible
$WorkingDir = Join-Path $Path "_framework"
if (!(Test-Path $WorkingDir)) { Throw "Wrong path $Path. current location must be wwwroot folder of published application." }
# Get All Items
$AllItems = Get-ChildItem $WorkingDir -Recurse
$DLLs = $AllItems | Where-Object { $_.Name -like '*.dll*' }
$BINs = $AllItems | Where-Object { $_.Name -like '*.bin*' }
# End script if no .dll are found
if ($DLLs) {
# Delete all current .bin files
if ($BINs) {
Remove-item $BINs.FullName -Force
}
# Change .dll to .bin on files and config
$DLLs | Rename-item -NewName { $_.Name -replace ".dll\b",".bin" }
((Get-Content "$WorkingDir\blazor.boot.json" -Raw) -replace '.dll"','.bin"') | Set-Content "$WorkingDir\blazor.boot.json"
# Delete Compressed Blazor files
if (Test-Path "$WorkingDir\blazor.boot.json.gz") {
Remove-Item "$WorkingDir\blazor.boot.json.gz"
}
if (Test-Path "$WorkingDir\blazor.boot.json.br") {
Remove-Item "$WorkingDir\blazor.boot.json.br"
}
# Do the same for ServiceWorker, if it exists
$ServiceWorker = Get-Item "$Path\service-worker-assets.js" -ErrorAction SilentlyContinue
if ($ServiceWorker) {
((Get-Content $ServiceWorker.FullName -Raw) -replace '.dll"','.bin"') | Set-Content $ServiceWorker.FullName
Remove-Item ($ServiceWorker.FullName + ".gz")
Remove-Item ($ServiceWorker.FullName + ".br")
}
}
else {
Write-Host "There are no .dll Files to rename to .bin"
}
}
Basically you need to navigate to the wwwroot folder of your published application and run the function there. e.g:
PS D:\inetpub\wwwroot\<appname>\wwwroot> Hide-BlazorDLL
Solution for me was to delete the obj and the bin folder in both the client and the server project folder
This error for some reason kept happening for me when I tested my application in an anonymous browser window (Google Chrome).
Try using a normal browser window if you're getting integrity errors.
Also, if you're using Cloudflare CDN don't forget to "Purge Everything" in the cache.
We have experienced this issue using Cloudflare auto minify feature. That feature removes any comments from html, js and other files - which some of the blazor .js files seems to contain.
This means that the hash of the file contents no longer matches the hash found in blazor.boot.json -> an integrity issue will be thrown and stop the app from loading.
Disabling the auto minify feature fixed the issue.
Tech Stack:
.NET 6.0.11
I had a similar issue. In the local machine, it is working fine. But when it is deployed through GitHub Actions, I get integrity checks error. I got this issue for Blazor WebAssembly ASP.NET Core Hosted (WebAssemblyPrerendered) project. Here is the fix I followed.
Added the .gitattributes file to the solution root folder.
Added the below code at the end of the file.
# blazor dlls - treat all .dll files as binary
*.dll binary

Referencing Lambda Source Files in Sibling Directory using Terraform

I am attempting to deploy a Lambda function using Terraform, where my source files are in a different directory adjacent to where I have my Terraform files. I want to have Terraform do the zipping of the source files for me and deploy them into the Lambda. Terraform doesn't seem to want to recognize that my files are there, though.
My directory structure:
project_root/
deployment/
terraform/
my-terraform.tf
function_source/
function.py
I want it to package everything in function_source directory (there is only one file there now, but may be more later) and drop it into the deployment directory.
My Terraform:
data "archive_file" "lambda_zip" {
type = "zip"
output_path = "../function.zip"
source_dir = "../../function_source/"
}
resource "aws_lambda_function" "my_lambda" {
filename = "${data.archive_file.lambda_zip.output_path}"
function_name = "my-function"
role = "${aws_iam_role.lambda_role.arn}"
handler = "function.handler"
runtime = "python3.7"
}
When I run this, though, I get the error message data.archive_file.lambda_zip: data.archive_file.lambda_zip: error archiving directory: could not archive missing directory: ../../function_source/
I have tried using absolute paths without success (which wouldn't be a good solution anyway). I have also tried creating the .zip file manually and hardcoding its directly in Lambda declaration, but it only works if I put the .zip file in my terraform directory. It seems Terraform can only see files in its own directory or below, but I'd rather not co-mingle my source files there. Is there a way to do this?
I am using Terraform v0.12.4

Create Nuget Pacakge with configuration of cloud config(ServiceDefinition.csdef) file

I would like to build Nuget package for my add-on which will be used by end user to install as startup task and after that they will upload their applications on window azure platform.
Let's take one simple web application and one cloud project now using Nuget end user will added add-on package it will add 2 files(exe & config) in web application project & add startup task to ServiceDefinition.csdef of cloud project as per shown in figure
How can i created this type of Nuget Pacakge?
Thanks in advance.
Update:
I have tried according with NICK's answer however i am getting problem with 2 webrole in cloud project according to shown in below fig.
and error i am getting as per below
Also i have one question that If i am installing that Nuget package with command line then how i can consider all webrole projects to add exe and config file in solution??
Nuget packages work based on a convention:
http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_convention_based_working_directory
As far as the exe and config you can do the following:
In your package directory make the following directories
mkdir lib (for the exe)
mkdir content (for the config)
All you have to do for the exe is drop the file in the lib directory and modify you .nuspec file just under the metadata node. There should be a "files" node (if not you can add one). Add something like this inside the files node:
<file src="content\my.exe" target="content\my.exe" />
The config is a little different. Just add a file named myname.config.transform to the content directory and add an entry into the .nuspec file:
A couple of things to note:
If the config file does not exist in your app it will add one for you.
You only have to add the nodes you want transformed if there is a file that already exists
The transform file will do a complete match on your node so if the following existed in
your config file:
<add key="test" value="myval"/>
And in your transform you had:
<add key="test" value="myval2"/>
The resulting file would look like:
<add key="test" value="myval"/>
<add key="test" value="myval2"/>
As far as adding the startup task, that's been a little more tricky for me (there might be a much better way). I use powershell in the install.ps1 (just like the files above but you create a "tools" directory for it):
param($installPath, $toolsPath, $package, $project)
#Modify the service config - adding a new Startup task
$svcConfigFile = $DTE.Solution.Projects|Select-Object -Expand ProjectItems|Where-Object{$_.Name -eq 'ServiceDefinition.csdef'}
$ServiceDefinitionConfig = $svcConfigFile.Properties.Item("FullPath").Value
[xml] $xml = gc $ServiceDefinitionConfig
#Create startup and task nodes
# So that you dont get the blank ns in your node
$startupNode = $xml.CreateElement('Startup','http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition')
$taskNode = $xml.CreateElement('Task','http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition')
$taskNode.SetAttribute('commandLine','my.exe')
$taskNode.SetAttribute('executionContext','elevated')
$taskNode.SetAttribute('taskType','simple')
$startupNode.AppendChild($taskNode)
#Check to see if the startup node exists
$modified = $xml.ServiceDefinition.WebRole.StartUp
if($modified -eq $null){
$modified = $xml.ServiceDefinition.WebRole
$modified.PrependChild($startupNode)
}
else{
$nodeExists = $false
foreach ($i in $xml.ServiceDefinition.WebRole.Startup.Task){
if ($i.commandLine -eq 'my.exe'){
$nodeExists = $true
}
}
if($taskNode -eq $null -and !$nodeExists){
$modified.AppendChild($taskNode)
}
}
$xml.Save($ServiceDefinitionConfig);
I hope this helps out.
--Nick

Assembly Versioning using CruiseControl.net

I have setup CruiseControl.net for a bunch of my projects which are related.
As a result a single project tag in CruiseControl has multiple SVN checkouts and then a bunch of msbuild tasks compile all the individual sln files.
I need to update the assembly version of all the solutions when this build is being done.
However, since i'm not using nant and not using MSBuild proj files, I am unsure on how to get this.
I wonder if I'm missing something obvious. I just need a solution which can be implemented by making appropriate changes in the ccnet.config file without requiring me to make changes to csproj files.
Thanks,
Anj
What about using a shared AssemblyInfo across your projects?
This is what we do for our products:
Each project has it's own AssemblyInfo.cs - this contains AssemblyTitle, AssemblyDescription, Guid, and other attributes that are unique to that assembly.
Each project also has two other Assembly Info files, note that these are added as a link rather than a direct file (VS -> Add -> Existing File -> Add as link (little down arrow next to add))
The two link files:
CompanyAssemblyInfo.cs - AssemblyCompany, AssemblyCopyright, AssemblyConfiguration, CLSCompliant, SecurityPermission, etc. Basically everything we want standard on all our assemblies.
ProductAssemblyInfo.cs - AssemblyProduct, AssemblyVersion, AssemblyFileVersion. This allows us to push the same version across to all assemblies from the one file.
Our CI and release process is more complicated, but that's at the heart of it - a single point (file) which controls the product version (assemblies, installers, everything!)
There's a task to do just what you're asking about.
You'll need to install the MSBuildCommunity tasks, found here.
Then, you can create something like this:
<PropertyGroup>
<MyAssemblyVersion>$(CCNetLabel)</MyAssemblyVersion>
</PropertyGroup>
<Target Name="GenAssemblyInfo">
<AssemblyInfo
ContinueOnError="false"
CodeLanguage="CS"
OutputFile="$(MSBuildProjectDirectory)\YourAssembly\AssemblyInfo.cs"
AssemblyTitle="blah"
AssemblyDescription="blah blah"
AssemblyCompany="Anj Software, Inc."
AssemblyProduct="Anj's Awesome App"
AssemblyCopyright="blah blah"
CLSCompliant="false"
AssemblyVersion="$(MyAssemblyVersion)"
AssemblyFileVersion="$(MyAssemblyVersion)"
/>
</Target>
Note that you can set a build number prefix in your ccnet.config file so that your assemblies will be numbered 2.1.0.x where x is the build number. That's how we do our version numbering where I work.
You'll still need to keep a default AssemblyInfo.cs file as part of each of the projects that make up your solution.
I use powershell for this. lpath is the path to the source code, and buildnum is my buildnumber I append. That is all I actually do with this. However, it should give you enough to change or set any or all of the other fields available. I pass in lpath and I get the buildnumber from the available environment variables in CC.NET and I can use this script over and over again, just changing what I pass in on the command line in the config file. I also have one that modifies the resource files for the C++ Code if that is actually what you need to modify.
$files = Get-ChildItem $lpath -recurse -filter *AssemblyInfo.cs -name
Foreach ($file in $files)
{
$file = $lpath + "\" + $file
$fileObject=get-item $file
$fileObject.Set_IsReadOnly($False)
$sr = new-object System.IO.StreamReader( $file, [System.Text.Encoding]::GetEncoding("utf-8") )
$content = $sr.ReadToEnd()
$sr.Close()
$content = [Regex]::Replace( $content, '(?<=\[assembly: AssemblyVersion\("[0-9].[0-9].[0-9].)[0-9]?[0-9]?[0-9]', $buildnum);
$content = [Regex]::Replace( $content, '(?<=\[assembly: AssemblyFileVersion\("[0-9].[0-9].[0-9].)[0-9]?[0-9]?[0-9]', $buildnum);
$sw = new-object System.IO.StreamWriter( $file, $false, [System.Text.Encoding]::GetEncoding("utf-8") )
$sw.Write( $content )
$sw.Close()
$fileObject.Set_IsReadOnly($True)
}

Resources