BizTalk ListApp command line - biztalk

I used the following code in c# to get policies\rules from deployed application in BizTalk server.
BTSTask.exe ListApp -ApplicationName:"EAISolution" -ResourceSpec:"c:\EAISolution.PolicyInf
o.xml" /Server:VHYDTRBELSUP-02 /Database:BizTalkMgmtDb
From above command I got the output as below
<?xml version="1.0" encoding="utf-16" ?>
<ResourceSpec xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ApplicationName="EAISolution" xmlns="http://schemas.microsoft.com/BizTalk/ApplicationDeployment/ResourceSpec/2004/12">
<Resources>
<Resource Type="System.BizTalk:BizTalkAssembly" Luid="EAIOrchestration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=97e0f507fd7fd10d" />
<Resource Type="System.BizTalk:BizTalkAssembly" Luid="EAIServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=97e0f507fd7fd10d" />
<Resource Type="System.BizTalk:BizTalkAssembly" Luid="FFSchemasTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=97e0f507fd7fd10d" />
<Resource Type="System.BizTalk:Rules" Luid="RULE/ProcessPurchaseOrder/1.0" />
<Resource Type="System.BizTalk:BizTalkBinding" Luid="Application/EAISolution" />
</Resources>
</ResourceSpec>
and from BizTalk server I got the below output using policy export in BizTalk server administration
<?xml version="1.0" encoding="utf-8" ?>
<brl xmlns="http://schemas.microsoft.com/businessruleslanguage/2002">
<ruleset name="ProcessPurchaseOrder">
<version major="1" minor="0" description="" modifiedby="username" date="2013-05- 27T12:04:55.6121122+05:30" />
<configuration />
<bindings>
<xmldocument ref="xml_31" doctype="RuleTest.PO" instances="16" selectivity="1" instance="0">
<selector>/*[local-name()='PurchaseOrder' and namespace-uri() ='http://EAISolution.PurchaseOrder']/*[local-name()='Item' and namespace-uri()='']</selector>
<selectoralias>/PurchaseOrder/Item</selectoralias>
<schema>....\PO.xsd</schema>
</xmldocument>
<xmldocument ref="xml_32" doctype="RuleTest.PO" instances="16" selectivity="1" instance="0">
<selector>/*[local-name()='PurchaseOrder' and namespace-uri()='http://EAISolution.PurchaseOrder']
</selector>
<selectoralias>/PurchaseOrder</selectoralias>
<schema>....\PO.xsd</schema>
</xmldocument>
</bindings>
<rule name="ApprovalRule" priority="0" active="true">
<if>
<compare operator="less than or equal to">
<vocabularylink uri="3f0e9bcc-6212-4e6a-853c-e517f157a626" element="d4eb2deb-06d3-42c4-af49-ceb21331b1cc" />
<lhs>
<function>
<xmldocumentmember xmldocumentref="xml_31" type="int" sideeffects="false">
<field>*[local-name()='Quantity' and namespace-uri()='']</field>
<fieldalias>Quantity</fieldalias>
</xmldocumentmember>
</function>
</lhs>
<rhs>
<constant>
<int>500</int>
</constant>
</rhs>
</compare>
</if>
<then>
<function>
<xmldocumentmember xmldocumentref="xml_32" type="string" sideeffects="true">
<field>*[local-name()='Status' and namespace-uri()='']</field>
<fieldalias>Status</fieldalias>
<argument>
<constant>
<string>Approved</string>
</constant>
</argument>
</xmldocumentmember>
</function>
</then>
</rule>
</ruleset>
</brl>
So please let me know how to get the output of second using command line.

BTSTask will only export the policy as part of an MSI (see below).
You could then extract the MSI (see How to extract msu/msp/msi fileds from the command line) to get the policy file.
From How to Import a Policy
BTSTask does not provide a specific command for importing (or exporting) policies; however you can use the ExportApp command of BTSTask to selectively export only the policies in an application that you want, including no other application artifacts. Then you can use the ImportApp command to import the .msi file into an application in a different BizTalk group. This is the approach described in this topic. When you do this, the policy is automatically imported and published in the BizTalk group and added to the specified application.
The below steps will get export the policy, but as part of an MSI.
From How to Export a Policy
Use the BTSTask ListApp command with the /ResourceSpec option to generate an XML file that lists the artifacts in the BizTalk application from which you want to export a policy, as described in ListApp Command.
Edit the XML file generated in the previous step, deleting all of the artifacts except for the policy or policies that you want to export.
Use the BTSTask ExportApp command, and specify the modified XML file for the /ResourceSpec parameter. For more information, see ExportApp Command.
BTSTask exports the specified policies and all of their associated vocabularies into an application .msi file.

Related

How to move nuget path in Visual Studio

Issue: I am trying to run a command PM> add-migration testing.
Detail: I know why I am getting this error. Due to security reasons, our company doesn't allow us to run any files inside C:\Users\name\... . so init.ps1 is getting blocked since i cant run inside that folder.
To fix, I moved my Visual Studio project code folder to the following path: C:\adminrun\repos. Here I admin access and I am allow to run any files. This lets me run project but init.ps1 is still inside C:\Users\name\.nuget\packages (this path is blocked)
Question: can I run add-migration command without PM?
Error:
& : File C:\Users\name.nuget\packages\microsoft.entityframeworkcore.tools\6.0.13\tools\init.ps1 cannot be loaded because its operation is blocked by software restriction policies, such as those created by using Group Policy.
At line:1 char:45
... rgs+=$_}; & 'C:\Users\name.nuget\packages\microsoft.entityfram ...
CategoryInfo: SecurityError: (:) [], PSSecurityException
FullyQualifiedErrorId : UnauthorizedAccess
C:\Users\name\AppData\Roaming\NuGet\NuGet.Config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
...
</configuration>
Step 1, change the downloaded NuGet package storage location:
According to the following file path, find a file named "NuGet.Config", or search for the file directly.
C:\Users{system username}\AppData\Roaming\NuGet
Open the "NuGet.Config" file, we can see the original file content as follows:
xml version="1.0" encoding="utf-8"?
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
packageSources>
configuration>
Replace its contents with the following and save:
xml version="1.0" encoding="utf-8"?
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
packageSources>
<config>
<add key="globalPackagesFolder" value=" The new path where you want the NuGet package to be stored " />
<add key="repositoryPath" value=" The new path where you want the NuGet package to be stored " />
config>
configuration>
Step2, modify the VS offline package reference address:
According to the following file path, find a file named "Microsoft.VisualStudio.Offline.config", or search for the file directly.
C:\Program Files (x86)\NuGet\Config
Open the "Microsoft.VisualStudio.Offline.config" file, we can see the original file content as follows:
xml version="1.0" encoding="utf-8"?
<configuration>
<packageSources>
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\"/>
packageSources>
configuration>
Replace its contents with the following and save:
xml version="1.0" encoding="utf-8"?
<configuration>
<packageSources>
<add key="Microsoft Visual Studio Offline Packages" value=" The new path where you want the NuGet package to be stored "/>
packageSources>
<config>
<add key="globalPackagesFolder" value=" The new path where you want the NuGet package to be stored " />
config>
configuration>
Step3, verify that the modified new path is successful:
Re-open a project with VS, uninstall a reference package in the project and reinstall it, find the reference item in the project reference list, right-click to open the property panel, in the "Path" column, we can clearly find the referenced The address has become the new address we just set.

MSDeploy setParameter.xml not transforming web.config

In my "myconfig" config profile transform for web.config i have this under appSettings:
<add key="my.config" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" value="derp" />
When I msbuild with this transform the value is transformed correctly. Now I want to build an msdeploy package and transform this value at deploy time.
I drop this parameters.xml in my project root:
<?xml version="1.0" encoding="utf-8" ?>
<parameters>
<parameter name="my.config" description="sdfsdfsdfsd" defaultValue="fart">
<parameterEntry kind="XmlFile"
scope="\\Web\.config$"
match="/configuration/appSettings/add[#my.config]/#value/text()" />
</parameter>
</parameters>
I build my package
msbuild app.csproj /T:Package /p:Configuration=myconfigprofile;PackageLocation=mydeploy.zip
I look at mydeploy.SetParameters.xml
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<setParameter name="IIS Web Application Name" value="Default Web Site/myApp_deploy" />
<setParameter name="my.config" value="fart" />
</parameters>
Then I go into parameters.xml inside of mydeploy.zip and see its there too:
<parameters>
<parameter name="my.config" description="sdkflsdjfldfj" defaultValue="fart">
<parameterEntry kind="XmlFile" scope="\\Web\.config$" match="/configuration/appSettings/add[#name='my.config']/#value/text()" />
</parameter>
</parameters>
looks good so far, then i deploy:
mydeploy.deploy.cmd /Y /M:server1
I look at web.config on the deploy server and the value is not transformed. I see no errors either, how do i debug this even?
When I run msbuild with parameters.xml present what magic happens there? How is the package preps to be able to transform web.config via parameters to web deploy?
This:
add[#name='my.config']
Had to be changed to this:
add[#key='my.config']
But the bigger question remains, how do I debug? I had to try a million times and just guess because I had zero errors/logs to help troubleshoot this. Is there verbose logging or some kind of validator or anything at all?
For debugging technet gave me this to try:
msbuild MyProject.proj /t:go /fl /flp:logfile=MyProjectOutput.log;verbosity=diagnostic
If you are using MSDeploy you can get the full output of the deployment by using the following:
msdeploy -verb:sync -source:dirpath=C:\WebDeployDemo\Src -dest:dirpath=C:\WebDeployDemo\Dst -setParamFile=C:\WebDeployDemo\ParameterFile.xml -verbose >msdeploysync-verbose.log
This helps with VSTS WebRM deployment debugging if you use the -verbose flag.
Sources:
https://learn.microsoft.com/en-us/iis/publish/troubleshooting-web-deploy/troubleshooting-web-deploy
https://blogs.msdn.microsoft.com/spike/2012/10/12/using-msdeploy-to-update-and-remove-sections-in-web-config-a-simple-example/

NLog does not create log files on ASP.NET Core project

I am new to using NLog with ASP.NET Core, so I have followed the guide here:
https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-(project.json)
I have created the following nlog.config file at the root of the project directory:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Warn"
internalLogFile="c:\temp\internal-nlog.txt">
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<!-- define various log targets -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="allfile" fileName="${basedir}\nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception}" />
<target xsi:type="File" name="ownFile-web" fileName="${basedir}\nlog-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}| ${message} ${exception}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
<target xsi:type="Null" name="blackhole" />
</targets>
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--Skip Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>
</nlog>
Inside a controller, I call a line like this one:
_logger.LogInformation("Entered CustomerRange method");
which returns the following in the output window in Visual Studio:
CustomerMgmtAPI.Controllers.CustomerController:Information: Entered CustomerRange method
However, the actual log files are never created by NLog. I was wondering if someone can point out the error in the NLog configuration here, since I have been reviewing the documentation of NLog for ASP.NET Core project and I can't find the error myself.
So the actual fix to the problem was the remove the first line from the nlog.config file:
<?xml version="1.0" encoding="utf-8" ?>
I remove this line and everything started working as expected. I also noticed that Visual Studio was giving me these errors when that line was present:
Invalid token 'Text' at root level of document.
Unexpected XML declaration. The XML declaration must be the first node in the document and no white space characters are allowed to appear before it.
It seems in this case that the NLog tutorial is broken, as I just took over this file from the sample for ASP.NET Core. I am using VS2017, so perhaps there is an incompatibility with this version of VS?
The dirty little secret about using NLog with ASP.NET Core is that you can configure and create logs just as you did in ASP.NET and ASP.NET MVC. You just use the regular NLog Nuget package like you normally would.
Just create an NLog.config in your root, etc. You don't even have to make any extra configurations in the config or elsewhere to get it to work. You just reference NLog in your class and then create a logger with the LogManager.
What this means is that you don't have all of the wireup in Program.cs etc.

Creating a server-level Web Deploy package

I can use Web Deploy to create packages that can be imported in existing IIS sites after the IIS server administrator manually creates the site for me.
Can I use Web Deploy to create packages that can be imported as a site instead of an application?
When I try to import my existing packages, I get this ugly error.
This might not be an answer to the question as was not able to find information on how to create a site package.
But as you asked for it in the comments, here's my approach on how to use the .cmd file created by the package process to install on site level.
Step 1
I create a package in our build process with msbuild. I've just added an extra step to our normal build that creates the project files in a deploy directory.
<Target Name="CreateDeploymentPackage">
<MSBuild Projects="$(CurrentProject).csproj" Targets="Package"
properties="Platform=$(Platform);
Configuration=$(Configuration);
DeployOnBuild=false;
DeployTarget=Package;
PublishProfile=$(Environment);
PackageLocation=$(DeployDirectory)\_PublishedWebsites\DeployPackage\$(CurrentProject).zip;
PackageAsSingleFile=true;
_PackageTempDir=$(PackageOutputDir)\temp;">
</MSBuild>
</Target>
I did set a specific PublishProfile to be able to pass a Web.config transformation for everything I know at build time.
Step 2
I've created a Parameters.xml in my project to be able to change params on install time of the package.
<?xml version="1.0" encoding="utf-8" ?>
<parameters>
<parameter name="Log4net to email"
description="Please provide the email address for Log4net."
defaultValue="itsupport#ourcompany.com"
tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="//log4net/appender[#name='SmtpAppender']/to/#value" />
</parameter>
<parameter name="Webservice address"
description="Please provide the endpoint address for the document web service"
defaultValue="http://test.services.ourcompany.com/Service.svc"
tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="//system.serviceModel/client/endpoint/#address" />
</parameter>
<parameter name="Elmah error email subject"
description="Please provide the elmah errormail subject"
defaultValue="Our Portal (Production) | An unexpected error occurred"
tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="//elmah/errorMail/#subject" />
</parameter>
</parameters>
You might think why there is no sitename and connection string in the Parameters.xml. But these are created automatically configurable when the deploy package is created and can be set with the SetParameters.xml
Read here: Why are some Web.config transforms tokenised into SetParameters.xml and others are not?
Step 3
Then I created a SetParameters-.xml for every environmen we have (prod, staging, test, dev). Here's one example for staging:
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<setParameter name="IIS Web Application Name" value="staging-sitename.ourcompany.com" />
<setParameter name="Log4net to email" value="webdev#ourcompany.com" />
<setParameter name="Webservice address" value="http://staging.services.ourcompany.com/Service.svc" />
<setParameter name="Elmah error email subject" value="Our Portal (Staging) | An unexpected error occurred" />
<setParameter name="PortalEntities-Web.config Connection String" value="metadata=res://*/Src.Entity.PortalEntities.csdl|res://*/Src.Entity.PortalEntities.ssdl|res://*/Src.Entity.PortalEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=test.sql.ourcompany.com;Initial Catalog=Portal_Staging;User Id=<userid>;Password=<password>;Application Name ='OurPortal';Connection Timeout=180;MultipleActiveResultSets=True"" />
</parameters>
Step 4
Then I excecute the install on the server with the following command
Portal.Web.deploy.cmd /Y -setParamFile:"Portal.Web.SetParameters-STAGING.xml"
There's still a lot of room for improvement, and I would like to automate more but this is what I have right now.
Basically instead of installing at the root of the site, deploy to a folder within the site!

.NET Web Deployment Tool with log4Net: Not overwriting logs

I'm using the Web Deployment Tool to build and release an MVC site from VS 2010 to a server running IIS. I also have log4net logging to a subdirectory off of the root of the web application I'm deploying to. I already figured out how to keep write permissions intact when deploying with this tool on that directory, but now I'm running into the problem that I'd rather not lose the logs when deploying, and also, the deploy is failing because the log file that log4net is using is "used by another process" (presumably w3wp) and won't let the deploy continue.
So, I'd like to preserve the log files and not delete or overwrite them, for auditing purposes. Is there a way to do that within the confines of the Web Deployment Tool?
EDIT: Here's the applicable bits of the log4net configuration, in Web.Config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" />
</configSections>
<log4net>
<appender name="RollingLog" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\Log.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="20" />
<maximumFileSize value="10MB" />
<datePattern value="yyyyMMdd" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="{%level}%date{MM/dd HH:mm:ss} - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLog" />
</root>
</log4net>
</configuration>
Found it by hunting around: there is a "skip" parameter you can tack on to the command when you call the pre-packaged deploy script. You HAVE to use a regular old CMD prompt for this; Powershell's crazy escaping of quotes makes it near-impossible to get right, so I gave up. Anyway, here's the end result I came up with:
.\MyProject.deploy.cmd /Y /M:MyServerName "-skip:skipAction=Delete,objectName=filePath,absolutePath=Logs"
"MyProject.deploy.cmd" being the name of the prepackaged deploy command, "MyServerName" being the name of the server I was deploying to, and "Logs" being the name of the folder I wanted to skip. This command seems to leave alone that Logs directory and deploy anything else that matters.
Source where I started to hone in on things: http://blogs.iis.net/msdeploy/archive/2009/04/23/what-has-changed-about-skip-replace-rules-in-rc.aspx
Set locking model of your appender to minimal lock and everything will be fine:
<appender name="RollingLog" type="log4net.Appender.RollingFileAppender">
...
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
...
</appender>
log4net.Appender.FileAppender (see remarks)

Resources