Getting intellisense to pick up intermediate cs file - visual-studio-2012

I have an XSD file (a DTD) which I run the XSD tool on to produce a C# file. I have modified my csproj's msbuild file in the following two places:
Added a special type for the item group:
<ItemGroup>
<SchemaFiles Include="Data\DeepZoomSchema.xsd">
</SchemaFiles>
</ItemGroup>
And then at the bottom of the file:
<Target Name="BeforeBuild" Inputs="#(SchemaFiles)" Outputs="#(SchemaFiles->'$(IntermediateOutputPath)%(Filename).cs')">
<XSD Language="CS" GenerateFromSchema="classes" SuppressStartupBanner="false" Namespace="DZParallelLib.Data" Sources="#(SchemaFiles)" AdditionalOptions="/out:$(IntermediateOutputPath)" />
<ItemGroup>
<Compile Include="#(SchemaFiles->'$(IntermediateOutputPath)%(Filename).cs')">
</Compile>
</ItemGroup>
</Target>
First of all, this project now compiles just fine. So I guess I have the hard part done. However, intellisense is broken in the sense that it never parses the DeepZoomSchema.cs output file.
In my ideal world, from the VS2012 IDE, I would like the .cs file to be found and parsed. I have found a way to do this, which is the following:
<ItemGroup>
<SchemaFiles Include="Data\DeepZoomSchema.xsd">
</SchemaFiles>
</ItemGroup>
<ItemGroup>
<Compile Include="#(SchemaFiles->'$(IntermediateOutputPath)%(Filename).cs')">
<Visible>False</Visible>
</Compile>
</ItemGroup>
And then the build step becomes a lot more simple:
<UsingTask TaskName="XSD" AssemblyName="Microsoft.Build.CppTasks.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Target Name="BeforeBuild" Inputs="#(SchemaFiles)" Outputs="#(SchemaFiles->'$(IntermediateOutputPath)%(Filename).cs')">
<XSD Language="CS" GenerateFromSchema="classes" SuppressStartupBanner="false" Namespace="DZParallelLib.Data" Sources="#(SchemaFiles)" AdditionalOptions="/out:$(IntermediateOutputPath)" />
</Target>
Now things are correctly parsed by the IDE (and the solution still builds), but it feels wrong. When I've written MS build rules in the past (and I admit, I've not done very many) I've always put the intermediate output files inside the build rule (as I did earlier on). Also, it feels like I should be using the "DependentUpon" tag here, and making them visible, just not shown by default in the IDE (sort of like a code-behind file??). Basically, the first solution feels like it is the "proper" way, but the IDE doesn't like it.
So, my question: Is there a better way to get what I want done than this second solution I've described?

Related

Nlog - Can I set an action when nlog is done writing to a file?

My current .net core nlog WebAPI config. I'm using:
<targets async="true">
Asynchronous target wrapper allows the logger code to execute more
quickly, by queueing messages and processing them in a separate
thread.
https://github.com/nlog/NLog/wiki/AsyncWrapper-target#async-attribute-and-asyncwrapper
<targets async="true">
<target name="jsonfile" xsi:type="File" fileName="/MyAPI${date:format=yyyy-MM-dd HH-mm-ss}.json" >
<layout xsi:type="JsonLayout">
<attribute name="Date" layout="${date:format=O}" />
</layout>
</target>
</targets>
This creates files every second:
MyAPI_2022-12-08 23-06-28.json
How how can I let nlog do something (f.ex. change the name or move it to another folder) when nlog is done writing to the file? I have a system (Splunk Universal Forwarder) that picks up the logs and I don't want it to pick up the file while it's being written to.
Thanks! :-)

How to decrease Hybris build time in case the data model does not need an update?

Lets say that a task needs to be done and there are no data model changes needed(i.e items.xml does not need to be touched).
For example a new Interceptor is needed for an existing Item Type. In this case I just need a new spring bean and a new Java class.
After I do the changes, If I run an "ant build" it takes approximately 1:30(one minute and a half), sometimes even more than that.
From what I noticed Hybris tries to check every extension that is included in localExtension.xml with their required extensions as well, and that is taking a lot of time.
How can I perform a faster build ? It should not take that much time since the only thing that is needed in my Interceptor case is to compile the new Interceptor class, and that's it.
I understand that when data model is changed the models.jar needs to be deleted, the new sources need to be generated and compiled in a new models.jar and that requires time. But in the more simple scenario it should work a lot faster.
PS: I know about JRebel but this question addresses the cases in which the developer does not have JRebel.
In platform/build.xml add below ant target:
<target name="compileExtensions" description="Compiles only the provided extensions">
<compile_only_specified_extensions/>
</target>
In platform/resources/ant/compiling.xml add the macro definition:
<macrodef name="compile_only_specified_extensions">
<sequential>
<foreachextprovidedincli>
<do>
<if>
<not>
<isset property="ext.#{extname}.warextension" />
</not>
<then>
<extension_compile extname="#{extname}" />
</then>
<else>
<external_extension_build extname="#{extname}"/>
</else>
</if>
</do>
</foreachextprovidedincli>
</sequential>
</macrodef>
Define foreachextprovidedincli in platform/resources/ant/util.xml
<macrodef name="foreachextprovidedincli">
<element name="do" optional="false" />
<attribute name="param" default="extname" />
<sequential>
<for list="${extensions.to.compile}" param="#{param}" delimiter=";">
<sequential>
<do />
</sequential>
</for>
</sequential>
</macrodef>
Now what I simply have to do to compile my classes is run the following command:
ant compileExtensions -Dextensions.to.compile="extensionName1;extensionName2;extensionName3"
With above command the build was reduced to 4 seconds.

Parameterizing Web.config fails for one of many parameters in Azure app deployment

I am lost. I've got a Web project that comes with a config file and several parameters which need to be set differently per target environment. I have an app setting and a connection string. The DEFINE values need to be replaced.
Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="HostUri" value="DEFINE"/>
...
</appSettings>
<connectionStrings>
<add name="DbConn" connectionString="DEFINE" providerName="System.Data.SqlClient"/>
</connectionStrings>
...
</configuration>
I've got a parameter specification which an Azure App Service Deploy task uses later during deployment. Here, I specified both values to be replaced.
parameters.xml:
<parameters>
<parameter name="HostUri" defaultValue="Replace me!">
<parameterEntry kind="XmlFile" scope="Web.config"
match="/configuration/appSettings/add[#key='HostUri']/#value" />
</parameter>
<parameter name="DbConn" defaultValue="Replace me!">
<parameterEntry kind="XmlFile" scope="Web.config"
match="/configuration/connectionStrings/add[#name='DbConn']/#connectionString" />
</parameter>
</parameters>
While the app setting HostUri is correctly replaced, the connection string DbConn stays untouched. I do not even get the default value set. It keeps its value DEFINE as originally set in the Web.config.
My gut tells me my XPath /configuration/connectionStrings/add[#name='DbConn']/#connectionString is incorrect, but it looks okay to me and follows what other posts have done, such as Cobus Bernard.
Any help is greatly appreciated.
I studied log files and found that MSBuild treats connection strings differently:
...
Adding declared parameter 'HostUri'.
Adding declared parameter 'DbConn'.
Adding declared parameter 'DbConn-Web.config Connection String'.
...
The last line led to an unwanted entry in the the generated file SetParameters.xml:
...
<setParameter name="HostUri" value="Replace me!" />
<setParameter name="DbConn" value="Replace me!" />
<setParameter name="DbConn-Web.config Connection String" value="DEFINE" />
...
So my XPath was correct, but this special directive put a DEFINE into my target Web.config. I found two solutions to this, primarily based on this SO question: How to Publish Web with msbuild?
1) Tweak your project file
Unload you Web project, edit the project file and add in your desired configuration the following line:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<!-- Add this line: --
<AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
...
</PropertyGroup>
The build process will pick this up and stops treating connection strings special.
I find this solution too hidden and people will forget so the alternative is a bit more explicit:
2) Configure MSBuild
Pass an explicit argument to MSBuild when the release package gets built:
msbuild /P:Configuration=Release;AutoParameterizationWebConfigConnectionStrings=false;...

how to reference assemblies from included file with msbuild?

I want to add an assembly reference to many projects.
These projects all include a Common.CSharp.targets file.
Is there any way that I can put the assembly reference in
the included file once? Instead of editing all the other
.csproj files?
This will be better in case we need to change the
reference in the future.
This simple Common.CSharp.targets file below doesn't work
because the reference doesn't appear in Visual Studio 2010
and the project won't compile due to the missing reference.
When I add this reference directly to the .csproj. It works.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<ItemGroup>
<Reference Include="PostSharp">
</ItemGroup>
</Project>

How do I enable logging in RhinoETL process?

I have nearly completed my first ETL process that uses Rhino ETL, and I've been able to figure out the way to use the API by referring to the tests.
Great. I have data moving through the pipeline and being written to the db.
However I can't seem to figure out how to enable logging.
the log4net assemblies are there, the log4net object is being created
the WithLoggingMixin class seems to be doing its thing (although I must admit I'm a bit fuzzy on exactly what that is)
in the log4net.config file I have a follingFileAppender set up, and it contains the following:
But no log file is created. When I make a call to Debug() in my code it doesn't do anything because log.IsDebugEnabled is false.
What am I missing?
In Rhino Etl 1.2.3, I was able to get logging to the console by adding the following to items the configuration section of the program's app.config file:
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="DEBUG" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
To log to destinations other than the console, the Common.Logging documentation has information on how to wire up log4net.
Okay. I dug through the [log4net documentation][1] and figured out a way to do it.
First of all I moved the log4net config into the App.config file (in a log4net section) and then executed
log4net.Config.XmlConfigurator.Configure();
during initialization. Now it works.
[1]: http://logging.apache.org/log4net/release/manual/configuration.html#.config Files "Apache log4net documentation"

Resources