Nuget Readonly Resources - c#

I'm creating a DTO generator to be shared between projects I have a ttinclude file with some logic in it. In my nuspec I'm including files like so:
<files>
<file src="T4Generators\AutoMapperExtensions.ttinclude" target="content\T4Generators\AutoMapperExtensions.ttinclude"/>
<file src="T4Generators\ConstGenerator.ttinclude" target="content\T4Generators\ConstGenerator.ttinclude"/>
<file src="T4Generators\DTOGenerator.ttinclude" target="content\T4Generators\DTOGenerator.ttinclude"/>
<file src="T4Generators\EnumGenerator.ttinclude" target="content\T4Generators\EnumGenerator.ttinclude"/>
</files>
Is there a way to make these files read-only, since they are shared between projects people have a tendency to make changes to the include instead of going to my source (this is an internal resource).

Related

ASP.net Include file which comes under exclude condition

I need to exclude certain dll's from the package which I am building. But I need to include only this dll - System.Threading.Tasks.Extensions. Is there a way I can force this dll in Include which would supersede exclude command.
<files>
<file src="**\*.dll" include ="**\System.Threading.*" exclude="**\System.*;**\Azure.*;**\Microsoft.Bcl.*;**\Microsoft.IdentityModel.*;**\BouncyCastle*.dll;**\GraphQL.*;**\LaunchDarkly.*;**\Oracle.*.dll;**\xunit*.dll;**\*Tests.dll;**\obj\**\*.*;**\itextsharp.dll;**\AjaxControlToolkit.dll;**\Newtonsoft.Json.dll;**\log4net.dll;**\Npgsql.dll" target="lib\net48" />
</files>

UWP Class Library NuGet package XamlParseException error

Currently I'm working on an UWP NuGet package for making it easier to create great popups and dialogs.
Currently the project is newborn and doesn't have so much controls but I tried to create a NuGet package for it to be a test for making sure it is all good.
Unless I'm using app with the class library referenced to the sample project all things working well but after downloading the library from NuGet I'm getting XamlParseException error.
I searched a bit and find it out that I should add some xaml, xbf or somethings in the output so I tried to add the following lines to my nuspec.
<files>
<!-- XAML controls -->
<file src="Controls\MessageBoxControls\MessageBoxControl.xaml" target="lib\netcore50\Controls\MessageBoxControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\MessageBoxControls\MessageBoxControl.xbf" target="lib\netcore50\Controls\MessageBoxControls"/>
<file src="Controls\PopupControlControls\PopupControl.xaml" target="lib\netcore50\Controls\PopupControlControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\PopupControlControls\PopupControl.xbf" target="lib\netcore50\Controls\PopupControlControls"/>
<file src="Controls\SlideupPopupControls\SlideupPopup.xaml" target="lib\netcore50\Controls\SlideupPopupControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\SlideupPopupControls\SlideupPopup.xbf" target="lib\netcore50\Controls\SlideupPopupControls"/>
</files>
But still I'm getting same error any idea how to solve it?
I should mention that the project is currently available on Github on the following link
https://github.com/NGame1/UWPPopupToolkit
and the NuGet package also is available here
https://www.nuget.org/packages/UWPPopupToolkit
Simply placing the content files in the lib folder of the nuget package will not automatically copy it into the build output folder, only the dll, pdb and xml files will be added into the output projects automatically.
Since your additional files are not the same type, so you cannot get what you want by your method. So I suggest you could try this:
Solution
1) create a folder called build on your root directory of your project and then add a file called <package_id>.props file.
Note: the file must be named the same as your nuget package so that it will work. For an example, if your nuget project named as UWPPopupToolkit.0.0.1-rc.nupkg, the file must be named as UWPPopupToolkit.props.
2) add these content into the UWPPopupToolkit.props file:
<Project>
<Target Name="OutputExtraFiles" BeforeTargets="Build">
<ItemGroup>
<File Include="$(MSBuildThisFileDirectory)..\File\**\*.*"></File>
</ItemGroup>
<Copy SourceFiles="#(File)" DestinationFiles="$(TargetDir)\%(RecursiveDir)%(Filename)%(Extension)"></Copy>
</Target>
</Project>
3) modify your UWPPopupToolkitSDK.nuspec file like this:
<files>
<!-- XAML controls -->
<file src="Controls\MessageBoxControls\MessageBoxControl.xaml" target="File\Controls\MessageBoxControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\MessageBoxControls\MessageBoxControl.xbf" target="File\Controls\MessageBoxControls"/>
<file src="Controls\PopupControlControls\PopupControl.xaml" target="File\Controls\PopupControlControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\PopupControlControls\PopupControl.xbf" target="File\Controls\PopupControlControls"/>
<file src="Controls\SlideupPopupControls\SlideupPopup.xaml" target="File\Controls\SlideupPopupControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\SlideupPopupControls\SlideupPopup.xbf" target="File\Controls\SlideupPopupControls"/>
<file src="build\UWPPopupToolkit.props" target="build" />
</files>
4) then repack your nuget project, before you install the new version of the nuget package, please clean the nuget caches first and also delete the bin, obj or any output folders of your main project.
=================================
Update 1
In my side, clean all nuget caches or delete all cache files under C:\Users\xxx(current user)\.nuget\packages and then install the new version of the nuget package, the target files are output to bin\x86\Debug\Controls,
If I install the new version 0.0.1.5-rc,everything works well. See this:
Not sure if your problem is that the files are missing or you want to put them into bin\x86\Debug\netcore50\Controls.
If your issue is the second, you should modify your UWPPopupToolkit.props,
use this:
<Copy SourceFiles="#(File)" DestinationFiles="$(TargetDir)netcore50\%(RecursiveDir)%(Filename)%(Extension)"></Copy>
After that, delete bin and obj folder and then rebuild your main project again.
Thanks to #Perry Qian-MSFT
Finally, I got able to fix the issue.
adding files like this
<files>
<!-- Dll -->
<file src="bin\Release\UWPPopupToolkit.dll" target="lib\netcore50" />
<!-- Resources -->
<file src="bin\Release\UWPPopupToolkit.pdb" target="lib\netcore50" />
<file src="bin\Release\UWPPopupToolkit.pri" target="lib\netcore50" />
<!-- IntelliSense -->
<file src="bin\Release\UWPPopupToolkit.XML" target="lib\netcore50" />
<!-- XAML control -->
<file src="bin\Release\UWPPopupToolkit\**\*.*" target="lib\netcore50\UWPPopupToolkit" />
<!-- Icon -->
<!--<file src="..\icon.png" target="images\" />-->
</files>
solved the problem.
You can find the result files here: UWPPopupToolkitSDK.nuspec | UWPPopupToolkit.props | UWP Popup Toolkit Github

Include *.resource.dll in nuget packages

When creating nuget package, I want to include all resources files.
Is it possible without specify one by one with tag in the .nuspec file ?
Maybe with wildcards ?
Just use some form of a wildcard. Here's an example I found.
<?xml version="1.0"?>
<package>
<metadata>...
</metadata>
<files>
<file src="lib\**" target="lib" />
</files>
</package>

Executing XmlTransform in Wix instead of on compile

I have a solution where I have different app.configs, given a different configuration. Drawback is that an installer (created using Wix) is created for a specific configuration. I would like to do this on install time, such that I can start the installer with a command line parameter to do the xml transformation, to be able to use the same installer in different environemnts (development, test, accpetance).
So, currently I have the transform in the csproj file:
<Target Name="AfterBuild">
<TransformXml Source="App.config" Transform="App.$(Configuration).config" Destination="$(OutputPath)\$(AssemblyName).exe.config" />
</Target>
What I want to do is:
msiexec /i installer.msi PROD
such that the transformation in app.PROD.config is executed. Is there a way in Wix to achieve that using the transformations?
Instead of transforming the original file at install time, it is easier to include all transformed app.config files into the MSI package and then choose the appropriate one during at install by passing the property value.
The snippet of the wxs file might look like this:
<Component Id="AppConfigDev" Guid="...">
<Condition>MODE = "DEV"</Condition>
<File Name="app.config" Id="app.dev.config" KeyPath="yes" Source="$(var.Source)\app.DEV.config" />
</Component>
<Component Id="AppConfigTest" Guid="...">
<Condition>MODE = "TEST"</Condition>
<File Name="app.config" Id="app.test.config" KeyPath="yes" Source="$(var.Source)\app.TEST.config" />
</Component>
<Component Id="AppConfigProd" Guid="...">
<Condition>MODE = "PROD"</Condition>
<File Name="app.config" Id="app.prod.config" KeyPath="yes" Source="$(var.Source)\app.PROD.config" />
</Component>
As a result, when you pass in the value of MODE through the command line, only one of the components above will be installed, and it will end up in the target directory as app.config.
Note that Windows Installer will throw a warning saying the conditions must be mutually exclusive in order for this technique to work. As long as MODE property can only have one value at a time, these conditions are mutually exclusive by definition, but the warning is there.

Log4net to generate log files dynamically

In my application I use log4net for logs creation. I want to create the log files in the location where the application gets installed.That is , the log files should be generated in c:\App_Instal_path\Logs(folder), if the application is installed under c:\.If it is D:\ then the log files should be under D:\App_Instal_path\Logs(folder). I have done like:
<appender name="ColoredFileAppender" type="log4net.Appender.RollingFileAppender" >
<file type="log4net.Util.PatternString"/>
<file value=***NEEDS TO BE FILLED*** />
Any responses would be really appreciated..
You can put the logfile near your exe file, if you write like this:
<file value="log-file.txt" />
In that case, you put the logfile in folder Logs, near your exe file:
<file value="Logs/log-file.txt" />
In that case, you put the logfile in system TMP folder:
<file value="${TMP}\log-file.txt" />
Look here for more information:
http://logging.apache.org/log4net/release/config-examples.html

Categories