Out of place of assembly with C #

I just finished setting up a custom build system for our existing C ++ code using inherited property sheets, which seems to be specific to the Visual C ++ product. Off-site creation requires that many project parameters be changed, and the inherited property sheets allow me to change all the necessary settings by simply adding a property sheet to the project. I am moving our team from C ++ / MFC for UI to C # and WPF, but I need to provide the same functionality out of place, I hope, with the same convenience. I cannot find a way to do this using C # projects. At first I looked to see if I could reference the MsBuild targets file, but could not find a way to do this. I know that I can just use MsBuild for everything, but it seems more complicated than necessary. Is there a way that I can define a macro for a directory and use it in the output path, for example?

+4
source share
3 answers

I'm not quite sure what an β€œoff-site” build system is, but if you just need a copy of the compiled files (or other resources) to other directories, you can do this by linking to the MSBuild build tasks.

In our projects, we move the compiled dlls to the lib folders and put the files in the right places after the build is complete. To do this, we created a custom build.target file that creates Target , Property and ItemGroup , which are then used to populate our external output folder.

Our custom goal file looks something like this:

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <ProjectName>TheProject</ProjectName> <ProjectDepthPath>..\..\</ProjectDepthPath> <ProjectsLibFolder>..\..\lib\</ProjectsLibFolder> <LibFolder>$(ProjectsLibFolder)$(ProjectName)\$(Configuration)\</LibFolder> </PropertyGroup> <Target Name="DeleteLibFiles"> <Delete Files="@(LibFiles-> '$(ProjectDepthPath)$(LibFolder)%(filename)%(extension)')" TreatErrorsAsWarnings="true" /> </Target> <Target Name="CopyLibFiles"> <Copy SourceFiles="@(LibFiles)" DestinationFolder="$(ProjectDepthPath)$(LibFolder)" SkipUnchangedFiles="True" /> </Target> <ItemGroup> <LibFiles Include=" "> <Visible>false</Visible> </LibFiles> </ItemGroup> </Project> 

The .csproj file in Visual Studio then integrates with this custom target file:

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="3.5" ... > ... <Import Project="..\..\..\..\build\OurBuildTargets.targets" /> <ItemGroup> <LibFiles Include="$(OutputPath)$(AssemblyName).dll"> <Visible>false</Visible> </LibFiles> </ItemGroup> <Target Name="BeforeClean" DependsOnTargets="DeleteLibFiles" /> <Target Name="AfterBuild" DependsOnTargets="CopyLibFiles" /> </Project> 

In short, this build script first tells MSBuild to load our build script, then adds the compiled file to the LibFiles ItemGroup, and finally binds our custom build targets DeleteLibFiles and CopyLibFiles to the build process. We set this for each project in our solution, so only files that are updated, deleted / copied, and each project is responsible for its own files (DLL, images, etc.).

Hope this helps. We apologize if I misunderstood what you mean by a system outside the assembly place, and this is completely useless to you!

+3
source

Is there a way I can define a macro for a directory and use it in the output path

Have you considered the events of pre-assembly and post-assembly of the project?

0
source

Actually, the events of pre-assembly and post-assembly seem to be extremely accessible for adding commands such as a batch file. Unfortunately, this will not help me create standard build directories for our projects. And the creation of these batch file events seems very close to 1980 for a modern language such as C #, IMO.

After digging a little more and experimenting, I found that you can add <Import> directives to your .csproj file. When you do this, a dialog box appears in the IDE warning you that your project has an unsafe entry point, but you can ignore it and you can make it not appear at all by editing the registry entry. This way, it will give me a way to get the variables containing the directory paths that I need into the .csproj file.

Now, to get a link to exit, unfortunately, when you add the line "$ (MySpecialPath) / Debug" in the field "Output path" and save the project, the characters $ and () are converted to hexadecimal, and your file will be placed in the Debug directory under the directory "$ (MySpecialPath)". Arrgghh. If you edit the .csproj file in a text editor, you can set it correctly, but it seems to work as long as the <Import> tag symbol appears before the <PropertyGroup> containing the output path.

So, I think that the solution for me will be to create a standard OurTeam.targets MsBuild file in a standard location, add an installer to change the registry so that it does not display warnings, and then create custom project templates, Import> this file, and also install output path to use the properties defined in the OurTeam.targets file. Unfortunately, this is more work and a less elegant solution than the mechanism for inheriting sheet properties in C ++.

0
source

Source: https://habr.com/ru/post/1276468/


All Articles