I have a project that is using NuGet packages. It also needs to target different framework versions per build config. I have them laid out in my csproj file something like this:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '2018|x64'">
<OutputPath>..\BuildFolder\2018</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '2019|x64'">
<OutputPath>..\BuildFolder\2019</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
I have more build configs than that, but those are examples where I have two different frameworks. The issue is that when I try to batch build the project with all release configs half of them fail depending on what my current config is. Using the two above, I can switch VS to my 2018 configuration and do a NuGet restore, then batch build both and 2018 will work and 2019 will fail with a 'Your project does not reference .NET Framework 4.7' errors. If I then switch to the 2019 config and do a NuGet restore and then try to batch build I get the reverse; 2019 works and 2018 tells me 'Your project does not reference .NET Framework 4.6.1'.
I also tried to put in the 'TargetFrameworks' object in the csproj file but then VS just spins and spins on opening and never opens the project.
How do I get this to work and recognize it to build all configs in batch? I suppose I could build them individually and will have to for now but that seems laborious and unnecessary...
Related
We´ve got a third party dll which is either x86 or x64, now we have to change the x64 dll with x86 dependent on the TargetPlatform. May someone tell how?
The first try was to override the dll with a post build script.
With Configuration Manager we could brand the build with x86, x64 and with the macro $(PlatformName) we could name the dll path relative to the platform (x64/x86)
Important to know is, that the macro has to be set in *.csproj file directly e.g.:
<Reference Include="DLLNAME, Version=4.9.0.0, Culture=neutral, PublicKeyToken=TOKEN,
processorArchitecture=$(PlatformName)">
<HintPath>Lib\$(PlatformName)\DLLNAME.dll</HintPath>
</Reference>
Also if there is a Plugin which should be compiled into the main-programm folder, the build path has to be changed in *.csproj file directly. E.g:
<OutputPath>..\..\bin\$(PlatformName)\Debug\Features\</OutputPath>
Thats because VS escapes the '$(' and ')'
EDIT:
Too fast. The <OutputPath> doesn´t understand macros. Therefore we had to change the outputpath for every Build-Configuration. Eg:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\bin\x86\Debug\Features\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\..\bin\x86\Release\Features\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
EDIT 2: For only x64 or x86 dependencies there is the Condition-Attribute which can seperate some cs-Files from x86 or x64 eg:
<Reference Condition="'$(Platform)'=='x64'" Include="STPadLibNet">
<HintPath>Lib\x64\DLLNAME.dll</HintPath>
</Reference>
and for some Clases u can use it like:
<Compile Condition="'$(Platform)'=='x64'" Include="MyClass.cs" />
I am working on an automated c# build that requires me to write/generate the csproj file and then compile it using the command line. For some reason while the dll is created without issue, the class it contains is dumped into the global namespace instead of the one I have specified in . Does anyone have any idea what might be going on here?
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>SimpleDependency.Test</RootNamespace>
<AssemblyName>simpledependency.test</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<ItemGroup>
<Compile Include="*.cs" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
I have msbuild set to .net 4.0, and am running this command on the command line:
msbuild /property:Configuration=Release /property:Platform=AnyCPU
I know that it generates the dll successfully because I then have another dependent project that uses the class I have defined in this project, but if I include:
using SimpleDependency.Test;
in that code, I get compile errors saying it cannot find namespace 'SimpleDependency'. Without this using statement, it compiles fine and works. Anyone have any thoughts?
Run MSBuild using the /preprocess:flattened.proj flag. Then load up the resulting file in an XML editor. My recent experience is that when properties are not being seen, it's overwritten someplace later (e.g. setting rather than appending to it) or something about conditions. That's a good start. You might also try getting MSBuildExplorer3 and see if that turns up anything. I'm not familiar with C# projects, but I think you should find where $(RootNamespace) is actually used for its effect, and trace backwards: is it ignored due to a condition, not getting the target variation you expected, etc. Once you know the lay of the land, run MSBuild with /verbosity:diag and grep through that for the target where it's (supposed to be) used, and see what it was thinking.
Copying the feedback from Pierre-Luc into an answer: The rootnamespace appears to only be a suggestion to the IDE to inject whenever creating classes. If the .cs files do not have a namespace specified, rootnamespace will not become the namespace for those classes. More information about that problem in this question.
I've recently upgraded some solution(s) to Visual studio 2013. All went OK apart from one which now generates the:
Symbol for the modules 'name' were not loaded.
...error every time I run it.
When I look in the modules debug window I can see against the dll (It's a web service dll)
Name Path Optimised User Code Symbol Status
dllName.dll Tempoary ASP.Net...etc. Yes No Skipped Loading...
If I look in the \bin I see the dll and it's coresponding .pdb file.
Checking the build menu for the project I can see Debug Info: full.
Cut a long story short everything looks fine to me except that it's not loading any symbols.
Any idea what I'm missing?
Update
It looks like if I run my solution though IIS express the issue goes away. But running though IIS (8) I still have this problem.
After painfully comparing two project files, one that worked and one that didn't I noticed that the proj that worked had:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
**<Optimize>false</Optimize>**
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Where as my one had
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
**<Optimize>true</Optimize>**
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
By setting the <Optimize> property to false all issues went away.
This answer also seems relevant as the .csproj.user file can be out of sync, I deleted it.
I am using MVC3 application,and am creating packages through TFS build.it was working fine when i am creating Packages through MSBuild.
Previously Website1 has my application(Website1/Application) in IIS,now i want to relocate my Application under Website2,like(Website2/Application),in the Package/PublishWeb properties.
But my TFS(MSBuild) Build was failed with following error
C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets
(3847): Web deployment task failed. (Site 'Website2' does not exist.).
do i need to change may Sitename any other place? Please help us to fixing this issue.
My configuration
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DeployOnBuild>true</DeployOnBuild>
<DeployTarget>MsDeployPublish</DeployTarget>
<MSDeployPublishMethod>InProc</MSDeployPublishMethod>
<CreatePackageOnPublish>true</CreatePackageOnPublish>
<MsDeployServiceURL>localhost</MsDeployServiceURL>
<DeployIisAppPath>Analytics/Application</DeployIisAppPath>
</PropertyGroup>
I am writing a fairly simple WPF desktop application and under build\configuration manager, release is not an option. The only available options are Debug, New, and Edit.
Anyone have an idea on why this is?
Related: the control library in the same solution does have release as a build option. It is only missing in the wpf app.
I figured it out.
To fix i copied the propertygroup tag for release build from the xml in the other project to the project that was missing it.
The propertygroup tag thing does fix the problem.
1) Open your project file in notepad.
2) Paste this after the "debug" propertygroup tag:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>