Conditional reference and compilation of project based on environment variable
I'm working on a library that is accessed by two types of users - company employees and then everyone else. Company employees have access to multiple Nuget packages from an internal Nuget feed that are not available to the public, I'll reference them in the post as the "proprietary" packages for convenience.
We have multiple projects in one solution - say project A, project B, and project C. Project A and Project B reference Project C, and Project C uses the "proprietary" packages.
What we would like to do is have one solution with two different build options - one for company employees and one for public. When a company employee builds the solution, it references and compiles Project C, and pull the "proprietary packages". When it's being built by someone else, Project A and Project B won't reference Project C, and Project C won't be compiled nor will it try to pull the "proprietary" packages.
Are there any suggestions on how to best accomplish this or any detailed blogs showing how this can be done?
I'm currently trying to set two different build configurations. In one, I try to define a constant like this in the build.props:
<PropertyGroup>
<!-- If build config is InternalEmployees -->
<DefineConstants>$(DefineConstants);InternalEmployees</DefineConstants>
</PropertyGroup>
Then in Project C, I added the following to
<ItemGroup>
<PackageReference Condition=" $(DefineConstants).contains(InternalEmployees)' Include="ProprietaryPackage" Version="1.1.1" />
</ItemGroup>
and then in both Project A and B, I'm trying to use #if processor directives
#if InternalEmployees
PropreitaryPackage.SomeMethod();
#endif
But this is currently not working - when I try to build, it fails by telling me that it can't find the proprietary packages.
c# msbuild .net-standard
add a comment |
I'm working on a library that is accessed by two types of users - company employees and then everyone else. Company employees have access to multiple Nuget packages from an internal Nuget feed that are not available to the public, I'll reference them in the post as the "proprietary" packages for convenience.
We have multiple projects in one solution - say project A, project B, and project C. Project A and Project B reference Project C, and Project C uses the "proprietary" packages.
What we would like to do is have one solution with two different build options - one for company employees and one for public. When a company employee builds the solution, it references and compiles Project C, and pull the "proprietary packages". When it's being built by someone else, Project A and Project B won't reference Project C, and Project C won't be compiled nor will it try to pull the "proprietary" packages.
Are there any suggestions on how to best accomplish this or any detailed blogs showing how this can be done?
I'm currently trying to set two different build configurations. In one, I try to define a constant like this in the build.props:
<PropertyGroup>
<!-- If build config is InternalEmployees -->
<DefineConstants>$(DefineConstants);InternalEmployees</DefineConstants>
</PropertyGroup>
Then in Project C, I added the following to
<ItemGroup>
<PackageReference Condition=" $(DefineConstants).contains(InternalEmployees)' Include="ProprietaryPackage" Version="1.1.1" />
</ItemGroup>
and then in both Project A and B, I'm trying to use #if processor directives
#if InternalEmployees
PropreitaryPackage.SomeMethod();
#endif
But this is currently not working - when I try to build, it fails by telling me that it can't find the proprietary packages.
c# msbuild .net-standard
How do you tell whether the person doing the compilation is an employee or not? As shown it looks like I could simply edit my environment variables and defeat this pseudo-security.
– No Refunds No Returns
Jan 3 at 3:32
I doubt the second code snippet is what you actually are using as it has missing quotes so the project file won't even load. Please post exact code to reproduce the issue. Other than that, if you get the condition correct (probably"$(DefineConstants.Contains('InternalEmployees'))"
),the principle you have here should work fine; the 'best' way to do this entirely depends on the situation so if a build configuration works for you then why not?
– stijn
Jan 3 at 8:45
add a comment |
I'm working on a library that is accessed by two types of users - company employees and then everyone else. Company employees have access to multiple Nuget packages from an internal Nuget feed that are not available to the public, I'll reference them in the post as the "proprietary" packages for convenience.
We have multiple projects in one solution - say project A, project B, and project C. Project A and Project B reference Project C, and Project C uses the "proprietary" packages.
What we would like to do is have one solution with two different build options - one for company employees and one for public. When a company employee builds the solution, it references and compiles Project C, and pull the "proprietary packages". When it's being built by someone else, Project A and Project B won't reference Project C, and Project C won't be compiled nor will it try to pull the "proprietary" packages.
Are there any suggestions on how to best accomplish this or any detailed blogs showing how this can be done?
I'm currently trying to set two different build configurations. In one, I try to define a constant like this in the build.props:
<PropertyGroup>
<!-- If build config is InternalEmployees -->
<DefineConstants>$(DefineConstants);InternalEmployees</DefineConstants>
</PropertyGroup>
Then in Project C, I added the following to
<ItemGroup>
<PackageReference Condition=" $(DefineConstants).contains(InternalEmployees)' Include="ProprietaryPackage" Version="1.1.1" />
</ItemGroup>
and then in both Project A and B, I'm trying to use #if processor directives
#if InternalEmployees
PropreitaryPackage.SomeMethod();
#endif
But this is currently not working - when I try to build, it fails by telling me that it can't find the proprietary packages.
c# msbuild .net-standard
I'm working on a library that is accessed by two types of users - company employees and then everyone else. Company employees have access to multiple Nuget packages from an internal Nuget feed that are not available to the public, I'll reference them in the post as the "proprietary" packages for convenience.
We have multiple projects in one solution - say project A, project B, and project C. Project A and Project B reference Project C, and Project C uses the "proprietary" packages.
What we would like to do is have one solution with two different build options - one for company employees and one for public. When a company employee builds the solution, it references and compiles Project C, and pull the "proprietary packages". When it's being built by someone else, Project A and Project B won't reference Project C, and Project C won't be compiled nor will it try to pull the "proprietary" packages.
Are there any suggestions on how to best accomplish this or any detailed blogs showing how this can be done?
I'm currently trying to set two different build configurations. In one, I try to define a constant like this in the build.props:
<PropertyGroup>
<!-- If build config is InternalEmployees -->
<DefineConstants>$(DefineConstants);InternalEmployees</DefineConstants>
</PropertyGroup>
Then in Project C, I added the following to
<ItemGroup>
<PackageReference Condition=" $(DefineConstants).contains(InternalEmployees)' Include="ProprietaryPackage" Version="1.1.1" />
</ItemGroup>
and then in both Project A and B, I'm trying to use #if processor directives
#if InternalEmployees
PropreitaryPackage.SomeMethod();
#endif
But this is currently not working - when I try to build, it fails by telling me that it can't find the proprietary packages.
c# msbuild .net-standard
c# msbuild .net-standard
edited Jan 2 at 23:02
Wai Ha Lee
6,126124166
6,126124166
asked Jan 2 at 22:43
sgonzalezsgonzalez
769
769
How do you tell whether the person doing the compilation is an employee or not? As shown it looks like I could simply edit my environment variables and defeat this pseudo-security.
– No Refunds No Returns
Jan 3 at 3:32
I doubt the second code snippet is what you actually are using as it has missing quotes so the project file won't even load. Please post exact code to reproduce the issue. Other than that, if you get the condition correct (probably"$(DefineConstants.Contains('InternalEmployees'))"
),the principle you have here should work fine; the 'best' way to do this entirely depends on the situation so if a build configuration works for you then why not?
– stijn
Jan 3 at 8:45
add a comment |
How do you tell whether the person doing the compilation is an employee or not? As shown it looks like I could simply edit my environment variables and defeat this pseudo-security.
– No Refunds No Returns
Jan 3 at 3:32
I doubt the second code snippet is what you actually are using as it has missing quotes so the project file won't even load. Please post exact code to reproduce the issue. Other than that, if you get the condition correct (probably"$(DefineConstants.Contains('InternalEmployees'))"
),the principle you have here should work fine; the 'best' way to do this entirely depends on the situation so if a build configuration works for you then why not?
– stijn
Jan 3 at 8:45
How do you tell whether the person doing the compilation is an employee or not? As shown it looks like I could simply edit my environment variables and defeat this pseudo-security.
– No Refunds No Returns
Jan 3 at 3:32
How do you tell whether the person doing the compilation is an employee or not? As shown it looks like I could simply edit my environment variables and defeat this pseudo-security.
– No Refunds No Returns
Jan 3 at 3:32
I doubt the second code snippet is what you actually are using as it has missing quotes so the project file won't even load. Please post exact code to reproduce the issue. Other than that, if you get the condition correct (probably
"$(DefineConstants.Contains('InternalEmployees'))"
),the principle you have here should work fine; the 'best' way to do this entirely depends on the situation so if a build configuration works for you then why not?– stijn
Jan 3 at 8:45
I doubt the second code snippet is what you actually are using as it has missing quotes so the project file won't even load. Please post exact code to reproduce the issue. Other than that, if you get the condition correct (probably
"$(DefineConstants.Contains('InternalEmployees'))"
),the principle you have here should work fine; the 'best' way to do this entirely depends on the situation so if a build configuration works for you then why not?– stijn
Jan 3 at 8:45
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014140%2fconditional-reference-and-compilation-of-project-based-on-environment-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014140%2fconditional-reference-and-compilation-of-project-based-on-environment-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How do you tell whether the person doing the compilation is an employee or not? As shown it looks like I could simply edit my environment variables and defeat this pseudo-security.
– No Refunds No Returns
Jan 3 at 3:32
I doubt the second code snippet is what you actually are using as it has missing quotes so the project file won't even load. Please post exact code to reproduce the issue. Other than that, if you get the condition correct (probably
"$(DefineConstants.Contains('InternalEmployees'))"
),the principle you have here should work fine; the 'best' way to do this entirely depends on the situation so if a build configuration works for you then why not?– stijn
Jan 3 at 8:45