I am trying to use Microsoft.Web.XmlTransform.dll to update an xml doc. I need to insert a new assembly element if one with the child element does not have a matching attribute name.
Transform:
<config>
<assembly xdt:Transform="Insert" xdt:Locator="Condition(./assembly/file/#name!='qux.dll')>
<file name='qux.dll>
</assembly>
</config>
Original Config:
<config>
<assembly>
<file name='foo.dll>
</assembly>
<assembly>
<file name='bar.dll>
</assembly>
<assembly>
<file name='qux.dll>
</assembly>
</config>
Output:
<config>
<assembly>
<file name='foo.dll>
</assembly>
<assembly>
<file name='bar.dll>
</assembly>
<assembly>
<file name='qux.dll>
</assembly>
<assembly>
<file name='qux.dll>
</assembly>
</config>
Expected output:
<config>
<assembly>
<file name='foo.dll>
</assembly>
<assembly>
<file name='bar.dll>
</assembly>
<assembly>
<file name='qux.dll>
</assembly>
</config>
I am assuming xdt:Locator="Condition(./assembly/file/#name!='qux.dll') is incorrect, but I can't for the life of me get it working as expected.
Cracked it:
<config>
<assembly xdt:Transform="InsertIfMissing" xdt:Locator="Condition(file/#name='qux.dll')>
<file name='qux.dll>
</assembly>
</config>
Related
My setup and what I try to achieve
My project is set up to use CMake, Ninja as my generator and MSVC as my compiler. I have an executable target A.exe and 2 shared library targets (B.dll and C.dll). I'm on Windows and use load-time linking by linking to their static counterparts B.lib and C.lib. The dependency of this targets goes as follows: A.exe -> B.dll -> C.dll (read "->" as "depends on").
Everything compiles and builds successfully, but when I try run the program I get this error:
The Application has failed to start because its side to side configuration is incorrect
The basic folder structure of my project:
\
| - A.cpp
| - B.cpp
| - C.cpp
| - A.manifest
| - B.manifest
| - C.manifest
| - CMakeListst.txt
Code
CMakeLists.txt:
cmake_minimum_required(VERSION 3.22.0)
project(test VERSION 0.1.0)
add_executable(
A
"A.cpp"
"A.manifest"
)
add_library(
B
SHARED
"B.cpp"
"B.manifest"
)
add_library(
C
SHARED
"C.cpp"
"C.manifest"
)
target_link_libraries(B C) # B -> C
target_link_libraries(A B) # A -> B
CPP files
A.cpp:
__declspec(dllimport) void B_test();
int main()
{
B_test();
return 0;
}
B.cpp:
__declspec(dllimport) void C_test();
__declspec(dllexport) void B_test()
{
C_test();
}
C.cpp:
#include <iostream>
__declspec(dllexport) void C_test()
{
std::cout << "Success" << std::endl;
}
Manifests
A.manifest:
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0"
>
<assemblyIdentity
type="win32"
name="A"
language="*"
processorArchitecture="amd64"
version="1.0.0.0"
/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="B"
language="*"
processorArchitecture="amd64"
version="1.0.0.0"
/>
</dependentAssembly>
</dependency>
</assembly>
B.manifest:
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0"
>
<assemblyIdentity
type="win32"
name="B"
language="*"
processorArchitecture="amd64"
version="1.0.0.0"
/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="C"
language="*"
processorArchitecture="amd64"
version="1.0.0.0"
/>
</dependentAssembly>
</dependency>
<file name="B.dll" />
</assembly>
C.manifest:
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0"
>
<!-- details about our side-by-side assembly-->
<assemblyIdentity
type="win32"
name="C"
language="*"
processorArchitecture="amd64"
version="1.0.0.0"
/>
<file name="C.dll" />
</assembly>
What I tried
As I read from the Microsoft Documentation, the C.manifest isn't actually necessary and all .dll files should be referenced in B.manifest, but that doesn't work either.
I tried to avoid using manifests, but if I do so, I get the same exact error.
What I wanted is to make my A.exe depend on B.dll which also depends on C.dll. I would like to know where I'm wrong and what can I do to achieve my goal.
With the help of fellow programmers in the comments and a bit of adding and removing lines from .manifest files I finally made it work. Thanks to Simon Mourier
A should declare B and C dlls –
Simon Mourier
What I was wrong about is declaring my B.dll and C.dll as separate private assemblies. What I had to do, in fact, is add the <file> tags to A.manifest as follows:
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0"
>
<assemblyIdentity
type="win32"
name="A"
language="cpp"
processorArchitecture="amd64"
version="1.0.0.0"
/>
<!-- Added the .dll's to application manifest -->
<file name="B.dll" />
<file name="C.dll" />
</assembly>
Also, the B.manifest and C.manifest were no longer needed, and I excluded them from the build:
cmake_minimum_required(VERSION 3.22.0)
project(test VERSION 0.1.0)
add_executable(
A
"A.cpp"
"A.manifest"
)
# removed "B.manifest"
add_library(
B
SHARED
"B.cpp"
)
# removed "C.manifest"
add_library(
C
SHARED
"C.cpp"
)
target_link_libraries(B C) # B -> C
target_link_libraries(A B) # A -> B
With that, everything works just fine and outputs correct
which IDE do the config file(package.des and xxx.prj ) belong to?
filename is xxx.prj and package.des
the content of package.des:
<?xml version="1.0" encoding="gb2312"?>
<proje target="market" targettype="exe" hasdebug="yes" hasmap="no" hasprofile="no" multithread="yes" warninglevel="2" workdir="." libs="" cppflags="-g -ggdb3 -fpermissive" ldflags="" arflags="">
<package name="utils" dir="../../src/base/utils"/>
<package name="ini" dir="../../src/base/ini"/>
<package name="json" dir="../../src/base/json"/>
<package name="redis" dir="../../src/base/redis"/>
<package name="printfc" dir="../../src/base/printfc"/>
<package name="thread" dir="../../src/base/thread"/>
<package name="baseexchapi" dir="../../src/business/engine"/>
<package name="Thostlink" dir="../../src/business/ctp"/>
<package name="linkmanager" dir="../../src/business/linkmanager"/>
<package name="market" dir="../../src/business/market"/>
</project>
the content of xxx.prj:
<?xml version="1.0" encoding="gb2312"?>
<packageDefine name="utils" version="1" type="cpp" includedir="." platform="all">
<parameter/>
<depend>
<package name="ini" version="1"/>
<package name="printfc" version="1"/>
</depend>
<cppfile>
<file name="Lib.cpp"/>
<file name="Logger.cpp"/>
</cppfile>
<headfile>
<file name="Lib.h"/>
<file name="Logger.h"/>
<file name="global.h"/>
</headfile>
<command/>
</packageDefine>
enter image description here
enter image description here
I want to use a CFG file to config link to a DLL for my app using QT Creator. Example Garena have file garena.exe.cfg. It links DLLs to path ./cef/:
"<?xml version ="1.0"?>
<configuration>
<dependency>
<file name="Qt5Core.dll" path="Qt5Core.dll" />
<file name="Qt5Gui.dll" path="Qt5Gui.dll" />
<file name="d3dcompiler_43.dll" path="cef\d3dcompiler_43.dll" />
<file name="d3dcompiler_47.dll" path="cef\d3dcompiler_47.dll" />
<file name="libcef.dll" path="cef\libcef.dll" />
<file name="libEGL.dll" path="cef\libEGL.dll" />
<file name="libGLESv2.dll" path="cef\libGLESv2.dll" />
<file name="widevinecdmadapter.dll" path="cef\widevinecdmadapter.dll" />
<file name="widevinecdmadapter.dll" path="cef\PepperFlash\pepflashplayer.dll" />
</dependency>
</configuration>"
How to create CFG file with QT?
I have a Visual Studio C++ project that creates a DLL for both x86 and x64 architectures in Debug and Release modes. I should publish this package as a nuget package with regards to these specifications. So I should have 4 DLLs in my package. My question is how to specify x86, x64 in my nuspec file. I was thinking whether it should be specified in the target field of each file but I can't find any documentation on how to exactly specify these specifications.
My nuspec file looks like the following:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<!-- Required elements-->
<id>counterpartylookup</id>
<version>0.0.0</version>
<description>counterpartylookup/v140/win32/x86/x64</description>
<authors>***</authors>
<!-- Optional elements -->
<!-- ... -->
<owners>...</owners>
<licenseUrl>***</licenseUrl>
<projectUrl>***</projectUrl>
<dependencies>
***
</dependencies>
<tags> {vc140, win32, x64, x86, dynamic, C++, native}</tags>
</metadata>
<files>
<file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="lib" />
<file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target="lib" />
<file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target="lib" />
<file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target="lib" />
</files>
<!-- Optional 'files' node -->
</package>
My question is how to specify x86, x64 in my nuspec file.
You need to place the dlls in a folder named runtimes within sub-folders named {platform}-{architecture}\lib{framework} or {platform}-{architecture}\native.
The folder structure:
\runtimes
\x86
\Debug
\Release
\x64
\Debug
\Release
The nuspec file is like:
<files>
<file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="runtimes\ x64\Release " />
<file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target=" runtimes\ x64\Debug " />
<file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target=" runtimes\ x86\Release " />
<file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target=" runtimes\ x86\Debug " />
</files>
The related documents: Architecture-specific folders and Adding the native implementation libraries.
Or you could try another:
1) create a file called <package_id>.targets file in your project folder. In your side, you should name it as counterpartylookup.targets:
write these under it:
<Project>
<ItemGroup Condition="'$(Platform)'=='x64' and '$(Cofiguration)'=='Debug'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x64\Debug\CounterPartyLookup.dll"></Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x86' and '$(Cofiguration)'=='Debug'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x86\Debug\CounterPartyLookup.dll"></Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x64' and '$(Cofiguration)'=='Release'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x64\Release\CounterPartyLookup.dll"></Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x86' and '$(Cofiguration)'=='Release'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x86\Release\CounterPartyLookup.dll"></Reference>
</ItemGroup>
</Project>
2) modify your nuspec file:
<files>
<file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="Reference\x64\Release" />
<file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target="Reference\x64\Debug" />
<file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target="Reference\x86\Release" />
<file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target="Reference\x86\Debug" />
<file src="counterpartylookup.targets" target="build"/>
</files>
3) repack your c++ project and then before you install the new one, you should delete all nuget caches under C:\Users\xxx(current user)\.nuget\packages
I need your valuable help, in reading a connection string value using regex -
Idea is to read the pattern using saltstack state file, and replace with VSTS variable.
Could you please help , how can I read the value ?
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication45-20140804053515.mdf;Initial Catalog=aspnet-WebApplication45-20140804053515;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization"
</entityFramework>
</configuration>
Below is my salt state file :
Thanks,
I use a Powershell script to replace the values of the connection string in the web.config.
After I "catch" the connection string I run this code:
$dbServer = [regex]::Match($connection, '(?i)data source=([^;]+)').Groups[1].Value
$newConnection = $connection.Replace($dbServer+';', $newSqlServerName+';')
$dbName = [regex]::Match($connection, '(?i)initial catalog=([^;]+)').Groups[1].Value
$newConnection = $newConnection.Replace($dbName+';', $newDbName+';')
So the Regex is:
For Data Source: (?i)data source=([^;]+)
For Initial Catalog: (?i)initial catalog=([^;]+)
For User name: (?i)user id=([^;]+)
For Password: (?i)password=([^;]+)