How to set the output path of several visual C# projects

后端 未结 4 1900
时光说笑
时光说笑 2020-12-24 07:08

I have a solution that contains several c# projects and I would like to be able to set the output path and other properties on all the projects together in a single place. P

相关标签:
4条回答
  • 2020-12-24 07:30

    Unfortunately, these bits of information such as output path are all stored inside the individual *.csproj files. If you want to batch-update a whole bunch of those, you'll have to revert to some kind of a text-updating tool or create a script to touch each of those files.

    For things like this (apply changes to a bunch of text files at once) I personally use WildEdit by Helios Software - works like a charm and it's reasonably priced.

    But I'm sure there are tons of free alternatives out there, too.

    0 讨论(0)
  • 2020-12-24 07:31

    Set the $(OutputPath) property in a common property sheet. Then delete that entry in all the project files you want to it to affect. Then import that property sheet into all your projects.

    For hundreds of projects that can be very tedious. Which is why I wrote a tool to help with this:

    https://github.com/chris1248/MsbuildRefactor

    0 讨论(0)
  • 2020-12-24 07:45

    A csproj file is already an msbuild file, this means that csproj files can also use an import element as described here. The import element is exactly what you require. You could create a Common.proj that contains something like:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="3.5"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <OutputPath>$(SolutionDir)output</OutputPath>
        <WarningLevel>4</WarningLevel>
        <UseVSHostingProcess>false</UseVSHostingProcess>
        <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    </PropertyGroup>
    </Project>
    

    You can import this Common.proj in each of your csprojs, for instance like so:

    <Import Project="..\Common.proj" />
    

    The import statement should precede any tasks that depend on the properties defined in Common.proj

    I hope this helps. I can't confirm your problems with the $(SolutionDir) variable I've used it many times. I do know however that this variable does not get set when you run an msbuild command via the commandline on a specific project that is contained in a solution. It will be set when you build your solution in Visual Studio.

    0 讨论(0)
  • 2020-12-24 07:53

    I would suggest you to use a build tool such as MSBuild or NAnt which would give you more flexibility on your builds. Basically the idea is to kick off a build using (in most cases) a single configurable build file.

    I would personally recommend NAnt.

    You could find an awesome tutorial on NAnt on JP Boodhoo's blog here

    0 讨论(0)
提交回复
热议问题